Documentation
Database

API Routes

Every server endpoint we expose, what it does, and who can call it.

Auth & integrations

MethodPathPurpose
GET/api/auth/googleInitiates Google OAuth. Redirects to Google consent screen with the full scope set.
GET/api/auth/google/callbackOAuth callback. Exchanges code for tokens, writes to integrations table.
GET/api/auth/callback/googleAlias for the above (legacy path).
POST/api/auth/invite-clientAdmin-only. Creates a Supabase user with role=client and sends magic link.
GET/api/google/propertiesLists every GA4 property the agency token can access. Used by admin client edit form.
GET/api/google/locationsLists every GBP location the agency token can manage.

Metric routes

All metric routes accept start_date and end_date unless marked otherwise.

PathRequired paramsSource
/api/metrics/ga4property_idGoogle Analytics Data API
/api/metrics/ga4/trafficproperty_idGA4 — daily users series
/api/metrics/ga4/pagesproperty_idGA4 — top pages
/api/metrics/ga4/acquisitionproperty_idGA4 — sessions by channel
/api/metrics/gscsite_urlSearch Console
/api/metrics/gsc/keywordssite_urlSearch Console — top 10 queries
/api/metrics/gbplocation_idGBP Performance API
/api/metrics/gbp/reviewsplace_id (no date range)Places API v1
/api/metrics/youtubechannel_id (no date range)YouTube Data API v3
/api/metrics/pagespeedurl (no date range)PageSpeed Insights v5
/api/metrics/google-adscustomer_idGoogle Ads API
/api/metrics/meta-adsaccount_idMeta Marketing API
/api/metrics/ghllocation_id, client_idGoHighLevel
/api/metrics/n8nclient_id (no date range)n8n live pull (conversations)
/api/metrics/seo-rankingsdomain (no date range)DataForSEO via cache
/api/metrics/sheets-rfmssheet_idGoogle Sheets API
POST /api/metrics/externalbearer tokenn8n push
/api/metrics/external/[clientId]clientId in pathRead external_metrics cache

Portal data

MethodPathPurpose
GET/api/portal/[clientId]Read all editable portal sections for a client.
PUT/api/portal/[clientId]Admin-only. Update one section (body: { section, data }).

Admin actions

MethodPathPurpose
POST/api/admin/create-client-userAdmin-only. Manually create a Supabase user bound to a client (alternative to invite flow).
POST/api/submit-requestAuthenticated. Records a Submit Request entry. Currently triggers a Slack notification.

Test routes

Unauthenticated, hardcoded to Denver. Used for debugging integrations without going through the UI:

  • /api/test/youtube
  • /api/test/gbp-reviews
  • /api/test/google-ads
  • /api/test/meta-ads
  • /api/test/meta-insights
  • /api/test/n8n
Production hygiene
Test routes should be removed or moved behind a feature flag before a production deployment that exposes them externally. They are useful in dev — risky in prod.

Standard response shape

Most metric routes return:

{
  connected: true | false,
  metrics: {
    metricName: { value: number, change: number, formatted: string }
  },
  ...auxiliaryFields
}

On failure they return { error: 'message' } with HTTP 400/403/500. The dashboard never throws on error — the affected card just stays empty (and is auto-hidden).