---
title: "Facebook Lead Ads → Light AI lead"
url: https://docs.light-ai.app/integrations/zapier/facebook-lead-ads.md
canonical_url: https://docs.light-ai.app/integrations/zapier/facebook-lead-ads
last_updated: 2026-11-07
summary: "A Zap that sends every Facebook and Instagram lead form submission into Light AI as a lead, never twice."
api_status: beta
related:
  - https://docs.light-ai.app/integrations/zapier
  - https://docs.light-ai.app/inbound
  - https://docs.light-ai.app/test-mode
  - https://docs.light-ai.app/idempotency
---

# 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](https://docs.light-ai.app/inbound/meta-and-lsa).

| 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](https://docs.light-ai.app/integrations/zapier#what-you-need) |
| 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](https://docs.light-ai.app/downloads/n8n/meta-lead-ads-to-light-ai.json) |

## 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 lead**

```javascript
// 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 Request**

```http
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

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](https://docs.light-ai.app/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](https://docs.light-ai.app/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

- [Facebook Lead Ads on Zapier](https://zapier.com/apps/facebook-lead-ads/integrations)
- [Webhooks by Zapier](https://help.zapier.com/hc/en-us/articles/8496288690317)
