Skip to main content

GHL Integration Tables

These tables support the GoHighLevel (GHL) integration for outbound calling automation. GHL is used as the execution layer for calls -- contacts are synced to GHL, calls are made in GHL, and call data flows back via webhooks.

ghl_integrations

Stores GHL location credentials and custom field mappings. Each GHL "location" (sub-account) gets its own row.

ColumnTypeNullableDefaultDescription
iduuidNOgen_random_uuid()Primary key
location_idtextNOGHL location ID (unique)
api_tokentextNOGHL API bearer token
nametextYESHuman-readable location name
is_activebooleanYEStrueWhether this integration is active
custom_field_mappingjsonbYESMaps Client Portal fields to GHL custom field IDs
created_attimestamptzYESnow()
updated_attimestamptzYESnow()

Custom Field Mapping

The custom_field_mapping JSONB maps Client Portal field names to GHL custom field IDs. This allows the sync-prospects-to-ghl function to populate custom fields when creating contacts in GHL.

{
"company_name": "custom_field_abc123",
"contact_title": "custom_field_def456",
"source": "custom_field_ghi789",
"linkedin_url": "custom_field_jkl012"
}

GHL API Details

SettingValue
Base URLhttps://services.leadconnectorhq.com
API Version2021-07-28
AuthBearer token from ghl_integrations.api_token

ghl_import_staging

Temporary staging table for batch imports from GHL. Records are staged here, matched to existing prospects/contacts, then processed.

ColumnTypeNullableDefaultDescription
iduuidNOgen_random_uuid()Primary key
batch_iduuidNOFK to ghl_import_batches.id
raw_datajsonbNORaw GHL contact/call data
statustextYES'pending'Processing status: pending, matched, imported, error, skipped
error_messagetextYESError details if processing failed
matched_prospect_iduuidYESFK to sales_prospects.id (if matched)
matched_contact_iduuidYESFK to contacts.id (if matched)
created_attimestamptzYESnow()

ghl_import_batches

Metadata for import batches. Each batch represents a single pull from GHL.

ColumnTypeNullableDefaultDescription
iduuidNOgen_random_uuid()Primary key
location_idtextNOGHL location ID
statustextYES'pending'pending, processing, completed, failed
total_recordsintegerYESTotal records in batch
processed_recordsintegerYES0Records processed so far
error_countintegerYES0Number of errors
created_byuuidYESFK to auth.users.id
completed_attimestamptzYESWhen processing finished
created_attimestamptzYESnow()

GHL Data Flow

GHL Webhook Deduplication

GHL fires two webhook hits per call -- one from the "Call Completed" workflow and one from the "Disposition" workflow. Both carry the same callId. The edge function deduplicates using external_call_id:

  • First hit: INSERT new sales_calls record
  • Second hit: UPDATE existing record with any additional data (transcript, disposition)
Mixed Case Call Status

GHL callStatus values are mixed case: Answered (715 occurrences), No answer (72), Busy (25), Failed (24), completed (23), Voicemail (4), Missed (1), Ringing (1). The webhook function normalizes all values to lowercase before comparing. Both "answered" and "completed" mean someone picked up.