> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailglyph.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Contacts

> Create, list, update, count, and delete contacts with the MailGlyph Node.js SDK.

Use a **secret key** client for contacts methods.

```ts theme={null}
import MailGlyph from 'mailglyph';

const client = new MailGlyph(process.env.MAILGLYPH_SECRET_KEY as string);
```

## List contacts (`contacts.list`)

Use cursor pagination for large lists:

```ts theme={null}
const page1 = await client.contacts.list({
  limit: 50,
  subscribed: true,
  search: 'john'
});

console.log(page1.data.length, page1.hasMore, page1.cursor);
```

Fetch the next page with `cursor`:

```ts theme={null}
if (page1.hasMore && page1.cursor) {
  const page2 = await client.contacts.list({
    limit: 50,
    cursor: page1.cursor
  });

  console.log(page2.data.length);
}
```

## Create a contact (`contacts.create`)

```ts theme={null}
const created = await client.contacts.create({
  email: 'user@example.com',
  subscribed: true,
  data: {
    firstName: 'John',
    plan: 'premium'
  }
});

console.log(created.id, created._meta?.isNew, created._meta?.isUpdate);
```

## Get one contact (`contacts.get`)

```ts theme={null}
const contact = await client.contacts.get(created.id);

console.log(contact.email, contact.subscribed);
```

## Update a contact (`contacts.update`)

```ts theme={null}
const updated = await client.contacts.update(created.id, {
  subscribed: false,
  data: {
    plan: 'pro'
  }
});

console.log(updated.subscribed, updated.data);
```

## Count contacts (`contacts.count`)

```ts theme={null}
const subscribedCount = await client.contacts.count({ subscribed: true });

console.log(subscribedCount);
```

## Delete a contact (`contacts.delete`)

```ts theme={null}
await client.contacts.delete(created.id);
```

See full details in the [Contacts API reference](https://docs.mailglyph.com/api-reference/contacts/listContacts.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.