# Contacts

Sync a Google account's contacts into your Zernio contacts, merged by email address with the people you already know from other channels.

A Google account connected with `scopes=contacts` copies its Google Contacts into the profile's [contacts](/contacts/list-contacts). You read them through `/v1/contacts`, like contacts from any other channel, and list the address book's groups with `GET /v1/contacts/groups`.

## Read the synced contacts

List the contacts that came from Google with the `platform` filter:

```bash
curl "https://zernio.com/api/v1/contacts?profileId=PROFILE_ID&platform=google" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

Each synced person gets one email channel per address on the Google account, shown as `Name (email)`. Read a contact's channels with `GET /v1/contacts/{contactId}/channels`.

Phone numbers are kept on those channels, in `metadata.phones` (E.164). They are used to find people you already know from WhatsApp, SMS or iMessage.

## Filter by group

List the groups of the address book:

```bash
curl "https://zernio.com/api/v1/contacts/groups?accountId=ACCOUNT_ID" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

The list holds Google contact labels, such as `Clients`, and the system groups the Contacts app shows (My Contacts, Starred, Family, Friends, Coworkers). Group ids look like `contactGroups/5a7c1d2e0b8f3a91`. Each group carries Google's `memberCount`.

Each synced channel carries the ids of its groups in `metadata.groups`. List the contacts in one group with the `group` filter, which needs `accountId`:

```bash
curl "https://zernio.com/api/v1/contacts?accountId=ACCOUNT_ID&group=contactGroups/5a7c1d2e0b8f3a91" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

Groups are read-only: Zernio never changes them in Google. Memberships are not stored while content retention is off.

## Search people

`GET /v1/contacts/autocomplete` finds people for an address field, read live from Google:

```bash
curl "https://zernio.com/api/v1/contacts/autocomplete?accountId=ACCOUNT_ID&q=ada&limit=10" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

It searches what the account's areas allow:

- With the `contacts` area, the user's Google Contacts.
- With the `directory` area, the coworkers in the user's Google Workspace directory and the people the user has emailed but never saved ("other contacts").

Each result has `name`, `email`, `emails`, `phones`, `company`, `jobTitle`, `photoUrl` and `source` (`contacts`, `directory` or `other`). `meta.sources` lists which sources were searched.

A personal Gmail account has no directory, so `directory` only adds "other contacts" there. To add the area to an account already connected, run the connect again with `scopes` including `directory`.

## When the sync runs

- Right after the account is connected with the `contacts` area, in the background.
- Every 15 minutes after that, picking up only what changed since the last run.

There is no endpoint to start a sync on demand.

## How contacts are matched

The sync never creates the same person twice:

1. A Google contact already synced is updated in place.
2. A Google contact whose address changed keeps its channel, moved to the new address.
3. A person already in your contacts with one of its email addresses gets the Google email channels instead of a second contact.
4. Otherwise, a person whose WhatsApp, SMS or iMessage channel has one of its phone numbers gets them.
5. Anyone else becomes a new contact.

A phone number shared by two different contacts, such as a family line, matches neither. The sync never merges two existing contacts.

Phone numbers are matched only when written in international form, such as `+34 612 345 678`. A number saved without its country code is kept out of matching, since its country is unknown.

A contact the sync created follows the address book when the person changes there. A contact it attached to keeps its own name, company and email, and the sync only fills them when empty.

A full resync, such as after an expired sync token, only fills empty fields and never overwrites a contact.

## How it behaves

- The sync reads the user's Google Contacts (People API connections). Contacts without an email address are skipped.
- It writes the name, company, photo and email, and keeps every address and phone number. Tags, custom fields and other channels are never touched.
- It is read-only: nothing is written back to Google.
- When a contact is deleted in Google, its Google channel is removed and `contact.deleted` fires. The contact stays, with its other channels and history.
- `contact.updated` fires when the sync adds or changes a contact, and never for a run that changed nothing.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| No contacts from Google | The account was connected without `contacts` | [Connect again](/platforms/google/connect#add-areas-later) with `contacts` in `scopes`. |
| A person is missing | They have no email address in Google Contacts | Add an email address in Google Contacts. The next sync, within 15 minutes, picks it up. |

## Related

- [List contacts](/contacts/list-contacts)
- [Get contact channels](/contacts/get-contact-channels)
- [Webhooks](/platforms/google/webhooks)