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:
- Saves the contact to Supabase (
contactstable) - Calls the Google People API to create or update the contact
- Writes the returned
google_contact_idback 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 = trueto 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:
- Check that
sync_to_google = trueon the contact (in Supabase or via Field contacts page) - Check that
google_contact_idis populated — if null, sync hasn't run for this contact yet - Run a manual sync from Settings
- Check Vercel function logs for
/api/contactsor/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).