Integrations
Facebook Lead Ads → Light AI lead
A Zap that sends every Facebook and Instagram lead form submission into Light AI as a lead, never twice.
Each new Meta lead form submission becomes a Light AI lead (and a project when it has a street address). The Meta lead id is sent as external_ref and Idempotency-Key, so a Zap that runs twice for one lead never creates a duplicate. Same flow as the n8n template.
| 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 | Facebook Lead Ads → New Lead (page and form) |
| Light AI API key | leads:write (add leads:read if you want the lead back instead of a receipt) |
| Other accounts | Facebook Lead Ads (a page admin connects the page) |
| n8n version | Meta Lead Ads → Light AI |
Build the Zap#
- Trigger: Facebook Lead Ads → New Lead. Pick the page and the form, then Test trigger (send a test lead from Meta's Lead Ads Testing Tool if the form has none yet).
- Action: Code by Zapier → Run JavaScript with the code below. Map the lead id, page id, form fields and ad/campaign ids into Input Data. Custom questions (address, service, message) map onto
street_address,city,state,zip,serviceandmessage. - Action: Webhooks by Zapier → Custom Request with the fields below. Map
bodyfrom the Code step into Data andidempotency_keyinto theIdempotency-Keyheader. - Test the step: the answer is the lead (
201, or200withreplayed: trueon a repeat) or a receipt (202) for a key withoutleads:read.
Code by Zapier: build the leadJavaScript
// Code by Zapier → Run JavaScript: builds the POST /v1/leads body.
// Input Data: map the Facebook Lead Ads fields onto these names (leave unused ones empty):
// lead_id, page_id, form_id, form_name, ad_id, campaign_id, created_time,
// full_name, first_name, last_name, email, phone, street_address, city, state, zip, service, message
const v = (name) => String(inputData[name] || '').trim() || null;
const full = v('full_name') || '';
const created = Date.parse(v('created_time') || '');
const lead = {
source: 'meta_lead_ad',
source_detail: v('form_name') || 'Meta lead ad',
external_ref: { system: 'meta_lead_ads', namespace: v('page_id'), id: v('lead_id') },
contact: {
first_name: v('first_name') || full.split(' ')[0] || null,
last_name: v('last_name') || full.split(' ').slice(1).join(' ') || null,
email: v('email'),
phone: v('phone'),
},
address: v('street_address')
? { line1: v('street_address'), city: v('city'), region: v('state'), postal_code: v('zip'), country: 'US' }
: null,
service_interest: v('service') || 'christmas_lights',
message: v('message'),
attribution: { utm_source: 'facebook', campaign_id: v('campaign_id'), ad_id: v('ad_id'), form_id: v('form_id') },
submitted_at: Number.isNaN(created) ? null : new Date(created).toISOString(),
};
if (!lead.external_ref.id) throw new Error('Map the Facebook lead id into lead_id');
return { body: JSON.stringify(lead), idempotency_key: 'meta-' + lead.external_ref.id };The body is built in code because values typed into a Custom Request's Data box are pasted as is: a quote or a line break in a homeowner's message would break the JSON.
| Custom Request field | Value |
|---|---|
| Method | POST |
| URL | https://api.light-ai.app/v1/leads |
| Data | {{body}} |
| Headers | Authorization = Bearer lai_test_…, Content-Type = application/json, Idempotency-Key = {{idempotency_key}} |
Webhooks by Zapier: Custom RequestHTTP
POST https://api.light-ai.app/v1/leads
Authorization: Bearer lai_test_…
Content-Type: application/json
Idempotency-Key: {{idempotency_key}}
{{body}}Field mapping#
| Facebook Lead Ads field | Light AI |
|---|---|
| Full name, or first and last name | contact.first_name, contact.last_name |
| Email, Phone number | contact.email, contact.phone (one of them is required) |
| Street address, City, State, Zip code | address.* (no street address: the lead waits for one, needs_address: true) |
| Lead id, Page id | external_ref (system: meta_lead_ads) |
| Form name | source_detail |
| Ad, campaign and form ids | attribution |
| Created time | submitted_at |
Test with test data#
- Create a test key: Settings → Developers → API keys → New key, mode Test, scope
leads:write(andleads:read). Put it in the Custom Request header while you build. - Run the Zap's test with Meta's test lead. A test key creates a test lead (
livemode: false) that the contractor never sees. - Test the Custom Request step twice: the second answer replays the first lead instead of creating a new one.
- Replace the key with a
lai_live_…key and turn the Zap on.
Errors, retries and duplicates#
- A
422naming/contactmeans the lead has neither an e-mail nor a phone: make one of them required in the Meta form. - Retries of the same lead are safe: the same
Idempotency-Keyreplays the first answer for 24 hours, and theexternal_refreturns the original lead forever. - 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#
- Meta's field names follow your form's questions. Run one real lead through before you rely on the Zap.