Light AIDocs Beta Open Light AI

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.

RequirementDetails
Light AI planPro or Enterprise (Pro trials included). Free and Plus have no API or webhooks.
Zapier planA paid plan (Professional, Team or Enterprise): multi-step Zap with Webhooks by Zapier. Details
TriggerFacebook Lead Ads → New Lead (page and form)
Light AI API keyleads:write (add leads:read if you want the lead back instead of a receipt)
Other accountsFacebook Lead Ads (a page admin connects the page)
n8n versionMeta Lead Ads → Light AI

Build the Zap#

  1. 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).
  2. 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, service and message.
  3. Action: Webhooks by Zapier → Custom Request with the fields below. Map body from the Code step into Data and idempotency_key into the Idempotency-Key header.
  4. Test the step: the answer is the lead (201, or 200 with replayed: true on a repeat) or a receipt (202) for a key without leads: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 fieldValue
MethodPOST
URLhttps://api.light-ai.app/v1/leads
Data{{body}}
HeadersAuthorization = 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 fieldLight AI
Full name, or first and last namecontact.first_name, contact.last_name
Email, Phone numbercontact.email, contact.phone (one of them is required)
Street address, City, State, Zip codeaddress.* (no street address: the lead waits for one, needs_address: true)
Lead id, Page idexternal_ref (system: meta_lead_ads)
Form namesource_detail
Ad, campaign and form idsattribution
Created timesubmitted_at

Test with test data#

  1. Create a test key: Settings → Developers → API keys → New key, mode Test, scope leads:write (and leads:read). Put it in the Custom Request header while you build.
  2. Run the Zap's test with Meta's test lead. A test key creates a test lead (livemode: false) that the contractor never sees.
  3. Test the Custom Request step twice: the second answer replays the first lead instead of creating a new one.
  4. Replace the key with a lai_live_… key and turn the Zap on.

Errors, retries and duplicates#

  • A 422 naming /contact means 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-Key replays the first answer for 24 hours, and the external_ref returns 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_limited with Retry-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-Key and the external_ref make the retry safe.

Notes#

  • Meta's field names follow your form's questions. Run one real lead through before you rely on the Zap.

Sources#