# Manage contacts with Node.js

Source: https://developer.nylas.com/docs/v3/sdks/node/manage-contacts/

This page explains how to manage contacts with the Nylas Node.js SDK and Contacts API.

## Before you begin

Before you start, you must have done the following tasks:

- [Installed and set up the Nylas Node.js SDK](/docs/v3/sdks/node/).
- [Authenticated one or more users](/docs/v3/sdks/node/#authenticate-users).

## List contacts

The example below lists the first and last names, email addresses, and IDs of the first 10 contacts in a user's contact list.

```js


const NylasConfig = {
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
};

const nylas = new Nylas(NylasConfig);

async function fetchContacts() {
  try {
    const identifier = "<NYLAS_GRANT_ID>";

    const contacts = await nylas.contacts.list({
      identifier,
      queryParams: {
        limit: 5,
      },
    });

    console.log("Contacts:", contacts);
  } catch (error) {
    console.error("Error fetching contacts:", error);
  }
}

fetchContacts();
```

## Create a contact

When you create a contact, Nylas syncs it to the user's provider. The following example creates a contact, assigns its attributes, and saves it to Nylas.

```js
async function createContact() {
  try {
    const contact = await nylas.contacts.create({
      identifier: "<NYLAS_GRANT_ID>",
      requestBody: {
        givenName: "My",
        middleName: "Nylas",
        surname: "Friend",
        notes: "Make sure to keep in touch!",
        emails: [{ type: "work", email: "swag@example.com" }],
        phoneNumbers: [{ type: "work", number: "(555) 555-5555" }],
        webPages: [{ type: "other", url: "nylas.com" }],
      },
    });

    console.log("Contact:", contact);
  } catch (error) {
    console.error("Error to create contact:", error);
  }
}

createContact();
```

For more information on Contact objects and their attributes, see the [Contacts references](/docs/reference/api/contacts/).

When you create a contact for a Google account, it renders like this on the provider:

<img
  src="/_images/google/contact-example.png"
  alt="A Google Contact card displaying the information for a contact named My Nylas Friend."
  style="height:300px;"
/>

For Microsoft Outlook, new contacts look like this:

<img
  src="/_images/microsoft/contact-example.png"
  alt="A Microsoft Contact card displaying the information for a contact named My Nylas Friend."
  style="height:300px;"
/>

## Delete a contact

To delete a contact from a user's account, you must get the contact's `id` and pass it as an argument to the `contacts.destroy()` function. You can use the same code from the [List contacts section](#list-contacts) to retrieve a contact's ID.

> **Warn:** 
> **The following code snippet deletes the contact you specify!** Make sure the contact is one that you actually want to delete.

```js
const deleteContact = async () => {
  try {
    await nylas.contacts.destroy({ identifier, contactId });

    console.log(`Contact with ID ${contactId} deleted successfully.`);
  } catch (error) {
    console.error(`Error deleting contact with ID ${contactId}:`, error);
  }
};

deleteContact();
```