Skip to content
Skip to main content

How to create and update contacts

Last updated:

A sales rep finishes a call and you want to save the new lead in their provider address book. Writing to each provider natively means juggling the Google People API, Microsoft Graph, EWS, hosted IMAP behavior, and CardDAV for iCloud and Yahoo. The Nylas Contacts API gives you one create, update, and delete flow across those systems.

This recipe walks through the three write operations and the provider rules that decide whether a write sticks.

Create a contact with a single POST to /v3/grants/{grant_id}/contacts. The body accepts 17 contact fields, and only given_name is required. Nylas writes the record into the user’s address book and returns the full contact with its new id, so you can store that ID and update or delete the contact later.

The request below sends a complete contact: name parts, two email addresses, two phone numbers, a birthday, groups, and a source of address_book. Every field except given_name is optional, so a minimal create can be just a name plus one email address. The response echoes the stored object with a server-assigned id.

Writes land in the address_book source on Google, Microsoft, EWS, hosted IMAP, native iCloud, and native Yahoo grants. Native iCloud and Yahoo grants write CardDAV data; a generic hosted IMAP grant doesn’t gain CardDAV support. You can’t create a contact in the read-only inbox or domain sources. The full field list lives in the Contacts API reference.

Update a contact with a PUT to /v3/grants/{grant_id}/contacts/{contact_id}, using the id you got back from the create call. You can omit top-level fields that you don’t want to change. If you include a nested object or array, send the complete replacement value for that field.

To change one phone number, read the contact first, replace the phone_numbers array, and send that complete array. The response normally returns the same id. For native CardDAV contacts, a provider-side move can change the href and public ID, so always persist the latest returned ID.

Updates need the same write scope as create. For generic hosted IMAP, updating an automatically generated inbox contact changes its source to address_book. Native iCloud and Yahoo inbox contacts are read-only, so update their CardDAV-backed address_book contacts instead.

Contact metadata has its own update rule: omission preserves it, an object replaces it, and {} clears it. A metadata-only request skips the provider write. See Add metadata to a contact for examples and the non-atomic provider-write boundary.

Delete a contact with a DELETE to /v3/grants/{grant_id}/contacts/{contact_id}. This is a single call with no request body, and it removes the contact from the user’s actual provider account, not just from a Nylas cache. The contact disappears from Gmail or Outlook too, so treat it as a destructive action and confirm with the user first.

The examples below delete one contact by ID. A successful delete returns a request_id so you can correlate the call in logs. There’s no soft-delete or trash step here, so once the call succeeds the record is gone from the provider.

Like update, delete only applies to address_book contacts. You can’t delete automatically generated inbox contacts through the API because the provider regenerates them from message participants.

The Nylas CLI creates and edits contacts without code: nylas contacts create adds one with a name, email, and company, and contacts update edits an existing contact by ID. Both write back to the provider, so changes show up in the user’s address book.

# Create a contact
nylas contacts create --first-name "Jane" --last-name "Smith" --email "[email protected]" --company "Acme"
# Update an existing contact by ID
nylas contacts update <contact-id> --company "Acme Inc" --job-title "Engineer"

One flag difference to watch: create uses --first-name and --last-name, while update uses --given-name and --surname (matching the API field names). Contact writes are supported on Google, Microsoft, EWS, hosted IMAP, native iCloud, and native Yahoo grants. See the contacts create and contacts update command reference.

Writes behave differently from reads, and a handful of provider rules decide whether a POST or PUT sticks. The most important one is the source field, which Nylas recognizes in three values: address_book, domain, and inbox. Creating a contact always uses address_book. For generic hosted IMAP, updating an inbox contact promotes it to address_book. Native iCloud and Yahoo inbox contacts and all domain contacts are read-only.

Write scopes are stricter than read scopes. Create, update, and delete all require Google’s https://www.googleapis.com/auth/contacts scope or Microsoft’s Contacts.ReadWrite. The read-only contacts.readonly or Contacts.Read scopes won’t authorize a write, so request the read-write scope at OAuth time if your app edits contacts. The Contacts API scopes page lists the exact strings per provider.

Field support varies by provider, and you’ll hit these limits in practice:

FieldGoogleMicrosoft / EWSNative iCloudNative YahooHosted IMAP
groupsSupportedMicrosoft only; EWS unsupportedSupportedSupportedProvider-dependent
web_pagesMultipleOne; type must be workMultipleMultipleAt most one
emailsMultipleUp to threeMultipleAt most oneProvider-dependent
manager_nameSupportedSupported where mappedUnsupportedUnsupportedProvider-dependent
office_locationSupportedSupported where mappedUnsupportedUnsupportedProvider-dependent

Groups also work differently on write. Pass groups as an array of { "id": "..." } objects, and reference only explicit groups that already exist at the provider. The API doesn’t create, rename, or delete Contact Group resources. Native iCloud and Yahoo membership writes use conditional CardDAV updates and can fail if provider state changes concurrently. To find valid group IDs first, see Organize contacts with groups.