DocsIntegrationsGoogle

Google Contacts Sync

Field automatically syncs new and updated contacts to Google Contacts under the assistant@codydesignbuild.com Google Workspace account. David's phone is linked to that account, so contacts appear on his phone within seconds.


How It Works

When a contact is created or updated via the Field API (/api/contacts), the route:

  1. Saves the contact to Supabase (contacts table)
  2. Calls the Google People API to create or update the contact
  3. Writes the returned google_contact_id back to Supabase

The sync only runs for contacts where sync_to_google = true (the default for new contacts).


Sync Direction

Field → Google (one-way)

Changes made directly in Google Contacts are not synced back to Field. Field is the source of truth.


Credentials

Three env vars are required in Vercel (cdb-field project):

| Variable | Purpose | |----------|---------| | GOOGLE_CLIENT_ID | OAuth 2.0 client ID | | GOOGLE_CLIENT_SECRET | OAuth 2.0 client secret | | GOOGLE_REFRESH_TOKEN | Long-lived refresh token for assistant@codydesignbuild.com |

These are stored encrypted in Vercel. The refresh token was obtained by Jerry during initial setup and doesn't expire (unless revoked).


Manual Full Sync

From Settings → Google Contacts Sync, you can trigger a full sync:

  • Sync Now button — pushes all contacts with sync_to_google = true to Google
  • Shows: last sync time, contacts synced, created/updated/pruned/error counts
  • Toggle: can disable auto-sync without changing env vars

Auto-sync also runs daily at 2 AM via /api/sync/google-contacts.


Troubleshooting

Contact isn't appearing on David's phone:

  1. Check that sync_to_google = true on the contact (in Supabase or via Field contacts page)
  2. Check that google_contact_id is populated — if null, sync hasn't run for this contact yet
  3. Run a manual sync from Settings
  4. Check Vercel function logs for /api/contacts or /api/sync/google-contacts

Sync fails with auth error:

The refresh token may have been revoked. Jerry needs to re-run the OAuth flow for assistant@codydesignbuild.com and update GOOGLE_REFRESH_TOKEN in Vercel.

Duplicate contacts in Google:

If google_contact_id is null and the contact already exists in Google, a new one gets created. Fix: manually set google_contact_id in Supabase to match the existing Google contact's resource name (people/c123456789).