Integrations
Website lead → HighLevel contact + opportunity
Every request from the Light AI website form becomes a HighLevel (GoHighLevel) contact with its answers in custom fields, plus an open opportunity.
Website form requests upsert the HighLevel contact (answers in lightai_* custom fields), open an opportunity in your pipeline and save the HighLevel contact id on the Light AI lead. It calls HighLevel's API with a Private Integration token, like the n8n recipe for website forms.
| Requirement | Details |
|---|---|
| Light AI plan | Pro or Enterprise (Pro trials included). Free and Plus have no API or webhooks. |
| Zapier plan | A paid plan (Professional, Team or Enterprise): multi-step Zap with Webhooks by Zapier. Details |
| Trigger | Webhooks by Zapier → Catch Raw Hook |
| Light AI webhook events | lead.created |
| Light AI API key | leads:read and leads:write (the write-back to a website lead needs both) |
| Other accounts | HighLevel sub-account with a Private Integration token (contacts and opportunities scopes) |
Build the Zap#
- Trigger: Webhooks by Zapier → Catch Raw Hook. Copy the webhook URL Zapier shows (raw, not the plain Catch Hook: the signature needs the exact body and the headers).
- In Light AI: Settings → Developers → Webhooks → Add endpoint. Paste the Zapier URL, Mode Test while you build, events
lead.created. Copy the signing secret (whsec_…, shown once). - Click Test on the endpoint (it sends a
ping), then Test trigger in Zapier and pick that request. - Action: Code by Zapier → Run JavaScript with the verification code below. Map Raw Body and the three headers into Input Data (in the field picker they are under Headers, labelled like Webhook Id; the exact labels can differ) and paste the secret into
secret. - Filter by Zapier: only continue if
verified(Boolean) is true andevent_type(Text) exactly matcheslead.created. - In the same Filter, add:
lead_sourceexactly matcheswebsite_widget,origin_typeexactly matchesembed, andlead_ref_highleveldoes not exist. - Action: Code by Zapier → Run JavaScript (build the contact, below). Type your location, pipeline and stage ids into Input Data and map Raw Body from the trigger.
- Action: Webhooks by Zapier → Custom Request: upsert the contact (below). Data =
bodyfrom the Code step. - Action (optional): Webhooks by Zapier → Custom Request: add a
light-aitag to the contact. Tags go in their own request because tags sent in an upsert replace the contact's existing ones. - Action: Webhooks by Zapier → Custom Request: create the opportunity with the Contact Id from the upsert answer.
- Action: Webhooks by Zapier → Custom Request: save the HighLevel contact id on the Light AI lead.
Verify the signature#
Zapier cannot check Light AI's HMAC signature by itself: a Catch Hook URL accepts anything anyone posts to it. This Code by Zapier step recomputes the Standard Webhooks signature, rejects deliveries older than 5 minutes and, once verified, returns the event as simple fields. Keep the Filter right after it so nothing unverified reaches your CRM.
// Code by Zapier → Run JavaScript, right after Webhooks by Zapier → Catch Raw Hook.
// Input Data (name on the left, value on the right):
// raw_body Raw Body, from the Catch Raw Hook step
// webhook_id the webhook-id header
// webhook_timestamp the webhook-timestamp header
// webhook_signature the webhook-signature header
// secret the endpoint's signing secret (whsec_…), typed in
// Next step: a Filter that only continues if "verified" is true.
const crypto = require('crypto');
const TOLERANCE_SECONDS = 300;
const raw = String(inputData.raw_body || '');
const id = String(inputData.webhook_id || '').trim();
const timestamp = String(inputData.webhook_timestamp || '').trim();
const signatures = String(inputData.webhook_signature || '').trim().split(' ');
const secret = String(inputData.secret || '').trim();
if (!raw || !id || !timestamp || !secret) return { verified: false, reason: 'missing body, header or secret' };
if (!/^\d+$/.test(timestamp) || Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) {
return { verified: false, reason: 'timestamp outside tolerance' };
}
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
const expected = Buffer.from('v1,' + crypto.createHmac('sha256', key).update(id + '.' + timestamp + '.' + raw).digest('base64'));
const valid = signatures.some((entry) => {
const candidate = Buffer.from(entry);
return candidate.length === expected.length && crypto.timingSafeEqual(candidate, expected);
});
if (!valid) return { verified: false, reason: 'signature mismatch' };
// Verified: flatten the event into fields later steps can map.
const event = JSON.parse(raw);
const o = (event.data && event.data.object) || {};
const text = (value) => (value === null || value === undefined ? '' : String(value));
const refs = (prefix, list) => Object.fromEntries((list || []).map((ref) => [prefix + '_ref_' + ref.system, text(ref.id)]));
const out = {
verified: true, reason: '', webhook_id: id, event_id: text(event.id), event_type: text(event.type),
livemode: event.livemode === true, origin_type: text(event.origin && event.origin.type),
origin_source_system: text(event.origin && event.origin.source_system),
organization_id: text(event.organization && event.organization.id),
grant_reference: text(event.grant && event.grant.external_reference),
};
const person = (p, address) => Object.assign(out, {
first_name: text(p.first_name), last_name: text(p.last_name),
full_name: [p.first_name, p.last_name].filter(Boolean).join(' '),
email: text(p.email), phone: text(p.phone),
address: text(address.formatted), address_line1: text(address.line1 || address.formatted), city: text(address.city),
region: text(address.region), postal_code: text(address.postal_code), country: text(address.country),
});
if (o.object === 'lead') {
person(o.contact || {}, o.address || {});
Object.assign(out, {
lead_id: text(o.id), lead_source: text(o.source), lead_status: text(o.status), needs_address: o.needs_address === true,
service_interest: text(o.service_interest), message: text(o.message), submitted_at: text(o.submitted_at),
form_id: text(o.form && o.form.id), form_name: text(o.form && o.form.name), mockup_status: text(o.mockup_status),
preview_looks: (o.preview_looks || []).join(', '),
answers_text: (o.form_answers || []).map((a) => a.question + ': ' + ((a.labels || []).join(', ') || text(a.value))).join('\n'),
project_id: text(o.project && o.project.id), project_app_url: text(o.project && o.project.app_url),
gclid: text(o.attribution && o.attribution.gclid),
}, refs('lead', o.external_refs));
}
if (o.object === 'quote') {
const client = o.client || {};
const totals = o.totals || {};
const money = (m) => (m && m.decimal) || '';
person(client, (o.property && o.property.address) || {});
Object.assign(out, {
quote_id: text(o.id), quote_status: text(o.status), quote_title: text(o.title), currency: text(o.currency),
total: money(totals.total), total_cents: totals.total ? totals.total.cents : 0, subtotal: money(totals.subtotal),
deposit: money(totals.deposit && totals.deposit.amount), truncated: o.truncated === true,
line_items_text: (o.line_items || []).filter((item) => item.selected !== false)
.map((item) => [item.name, item.quantity !== null && item.quantity !== undefined ? item.quantity + ' ' + text(item.unit) : '', money(item.amount)].filter(Boolean).join(' · '))
.join('\n'),
sent_at: text(o.sent_at), approved_at: text(o.approved_at), declined_at: text(o.declined_at), expires_at: text(o.expires_at),
view_count: (o.engagement && o.engagement.view_count) || 0, first_viewed_at: text(o.engagement && o.engagement.first_viewed_at),
app_url: text(o.links && o.links.app_url), customer_url: text(o.links && o.links.customer_url),
rep_name: text(o.assigned_rep && o.assigned_rep.name), rep_email: text(o.assigned_rep && o.assigned_rep.email),
project_id: text(o.project && o.project.id), client_id: text(client.id), lead_id: text(o.lead && o.lead.id),
}, refs('project', o.project && o.project.external_refs), refs('client', client.external_refs), refs('quote', o.external_refs));
}
return out;The secret sits in the Zap, so anyone who can edit the Zap can read it: keep the Zap in a private folder and rotate the secret if it is shared. The same file is in Downloads.
Build the contact#
// Code by Zapier → Run JavaScript: builds the HighLevel contact upsert body for a website lead.
// Input Data: location_id, pipeline_id, stage_id (typed in), raw_body (Raw Body from the Catch Raw Hook step)
const event = JSON.parse(inputData.raw_body);
const lead = event.data.object;
const contact = lead.contact || {};
const address = lead.address || {};
const answers = lead.custom_fields || {};
const labels = Object.fromEntries((lead.form_answers || []).map((a) => [a.key, (a.labels || []).join(', ')]));
const value = (v) => (Array.isArray(v) ? v.join(', ') : v !== null && typeof v === 'object' ? JSON.stringify(v) : String(v));
// Each answer goes to a HighLevel custom field lightai_<question key> (create them under Settings → Custom Fields).
const customFields = Object.entries(answers).map(([k, v]) => ({ key: 'lightai_' + k.replace(/[^a-z0-9_]/gi, '_').toLowerCase(), field_value: labels[k] || value(v) }));
if (lead.form) customFields.push({ key: 'lightai_form', field_value: lead.form.name });
const name = [contact.first_name, contact.last_name].filter(Boolean).join(' ') || 'Website request';
const body = {
locationId: inputData.location_id,
firstName: contact.first_name || undefined, lastName: contact.last_name || undefined,
email: contact.email || undefined, phone: contact.phone || undefined,
address1: address.line1 || address.formatted || undefined, city: address.city || undefined,
state: address.region || undefined, postalCode: address.postal_code || undefined, country: address.country || undefined,
// No tags here: tags in an upsert replace the contact's existing tags.
source: 'Light AI website form', customFields,
};
return {
body: JSON.stringify(body),
// A JSON string (with its quotes), safe to paste into the opportunity request body.
opportunity_name_json: JSON.stringify(name + ' · Christmas lights'),
location_id: inputData.location_id, pipeline_id: inputData.pipeline_id, stage_id: inputData.stage_id, lead_id: lead.id,
};HighLevel requests#
| Custom Request field | Value |
|---|---|
| Method | POST |
| URL | https://services.leadconnectorhq.com/contacts/upsert |
| Data | {{body}} |
| Headers | Authorization = Bearer pit-…, Content-Type = application/json, Version = 2021-07-28 |
POST https://services.leadconnectorhq.com/contacts/upsert
Authorization: Bearer pit-…
Content-Type: application/json
Version: 2021-07-28
{{body}}| Custom Request field | Value |
|---|---|
| Method | POST |
| URL | https://services.leadconnectorhq.com/contacts/{{Contact Id}}/tags |
| Data | {"tags": ["light-ai"]} |
| Headers | Authorization = Bearer pit-…, Content-Type = application/json, Version = 2021-07-28 |
POST https://services.leadconnectorhq.com/contacts/{{Contact Id}}/tags
Authorization: Bearer pit-…
Content-Type: application/json
Version: 2021-07-28
{"tags": ["light-ai"]}| Custom Request field | Value |
|---|---|
| Method | POST |
| URL | https://services.leadconnectorhq.com/opportunities/ |
| Data | {"locationId": "{{location_id}}", "pipelineId": "{{pipeline_id}}", "pipelineStageId": "{{stage_id}}", "name": {{opportunity_name_json}}, "status": "open", "contactId": "{{Contact Id}}"} |
| Headers | Authorization = Bearer pit-…, Content-Type = application/json, Version = 2021-07-28 |
POST https://services.leadconnectorhq.com/opportunities/
Authorization: Bearer pit-…
Content-Type: application/json
Version: 2021-07-28
{"locationId": "{{location_id}}", "pipelineId": "{{pipeline_id}}", "pipelineStageId": "{{stage_id}}", "name": {{opportunity_name_json}}, "status": "open", "contactId": "{{Contact Id}}"}opportunity_name_json already carries its quotes, so it goes into the body without them.
Write the contact id back#
| Custom Request field | Value |
|---|---|
| Method | PUT |
| URL | https://api.light-ai.app/v1/leads/{{lead_id}}/external_refs/highlevel |
| Data | {"id": "{{Contact Id}}", "namespace": "{{location_id}}"} |
| Headers | Authorization = Bearer lai_test_…, Content-Type = application/json |
PUT https://api.light-ai.app/v1/leads/{{lead_id}}/external_refs/highlevel
Authorization: Bearer lai_test_…
Content-Type: application/json
{"id": "{{Contact Id}}", "namespace": "{{location_id}}"}Field mapping#
| HighLevel | Light AI |
|---|---|
firstName, lastName, email, phone | contact.* |
address1, city, state, postalCode | address.* |
customFields lightai_<key> | Each custom_fields answer, with its display label from form_answers |
lightai_form | form.name |
| Opportunity | Customer name · Christmas lights, status: open, in your pipeline and stage |
Test with test data#
Build and test against test data only: a lai_test_… key, a Test endpoint and the test helpers. Test objects never reach the contractor's pipeline, never e-mail anyone and are deleted after 7 days.
- Create a test key: Settings → Developers → API keys → New key, mode Test, scopes
leads:readandleads:write. - API test leads have
source: zapier, so turn off the two website conditions in the Filter for the test run, and back on before going live.
curl -X POST "https://api.light-ai.app/v1/leads" \
-H "Authorization: Bearer $LIGHT_AI_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"source": "zapier",
"contact": {
"first_name": "Dana",
"last_name": "Reyes",
"email": "dana@example.com",
"phone": "+1 512 555 0134"
},
"address": {
"line1": "4102 Oak Hollow Dr",
"postal_code": "78731"
}
}'const response = await fetch('https://api.light-ai.app/v1/leads', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.LIGHT_AI_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
'Content-Type': 'application/json',
},
body: JSON.stringify({
"source": "zapier",
"contact": {
"first_name": "Dana",
"last_name": "Reyes",
"email": "dana@example.com",
"phone": "+1 512 555 0134"
},
"address": {
"line1": "4102 Oak Hollow Dr",
"postal_code": "78731"
}
}),
});
const data = await response.json();import os, uuid, requests
response = requests.post(
"https://api.light-ai.app/v1/leads",
headers={
"Authorization": f"Bearer {os.environ['LIGHT_AI_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
},
json={
"source": "zapier",
"contact": {
"first_name": "Dana",
"last_name": "Reyes",
"email": "dana@example.com",
"phone": "+1 512 555 0134"
},
"address": {
"line1": "4102 Oak Hollow Dr",
"postal_code": "78731"
}
},
)
data = response.json()- Pick the
lead.createdrequest in Test trigger, test each step, then check the contact and opportunity in HighLevel (use a test sub-account if you have one). - Go live: restore the Filter, add a Live endpoint, paste its secret, switch to a
lai_live_…key and delete the test endpoint.
Errors, retries and duplicates#
- Duplicates: HighLevel's upsert matches the contact on e-mail or phone, and the Filter skips leads that already carry a
highlevelreference. If the opportunity step fails after the upsert, fix it and replay: the upsert is safe to repeat. - HighLevel answers
401for a token without the contacts or opportunities scope and422for a wrong pipeline or stage id. - Zapier answers
200the moment the hook receives a request, so Light AI records the delivery as delivered. Failures after that show up in Zap history, not in Light AI's delivery log. - To resend after fixing a step, use Light AI's Retry in the delivery log (
POST /v1/webhook_deliveries/{id}/retry) or Replay (POST /v1/webhook_endpoints/{id}/replay): both sign the delivery again. A Zapier re-run that executes the verify step more than 5 minutes after the delivery returnsverified: falseby design. - Deliveries are at least once and replays reuse the
webhook-id, so the same event can reach the Zap twice. Each recipe below has a guard against duplicates; keep it. - Events are not ordered. Map from the event you receive (it is rendered when it is sent) rather than assuming an earlier one arrived first.
- Turning the Zap off makes Zapier answer
404(it can take hours to start). Light AI then retries for about 4 days and disables the endpoint, so disable or delete the endpoint in Light AI when you turn a Zap off. - Light AI errors are JSON with a
code(see Errors):401 invalid_api_key(wrong or mistyped key),403 insufficient_scope(the key lacks the scope above),422 validation_failed(errors[]names each field),429 rate_limitedwithRetry-After(60 writes a minute per key by default, see Rate limits). - Turn on Zapier's Autoreplay where your plan has it, or replay a failed run by hand: the
Idempotency-Keyand theexternal_refmake the retry safe.
Notes#
- No-code alternative: HighLevel's Zapier app (LeadConnector) has Add/Update Contact and Add/Update Opportunity actions; map the verify step's fields into them instead of the HighLevel requests.
- Partners serving many locations: set each grant's
external_referenceto the HighLevellocationIdand mapgrant_referenceintolocation_id.