Guides
Leads

Lead ads and webhook

Lead forms, the ad that uses them, the leadgen webhook subscription, the payload, reading the lead, test leads and retries.

In a lead ad, the person fills in a form without leaving Facebook or Instagram. Meta notifies your application through the leadgen webhook, with the lead id, and the application fetches the lead's data through the API.

1. Create the form

Forms belong to a Page and require the Page access token (from /me/accounts) with pages_manage_ads:

bash
curl -s 'https://meta-ads.mimicr.dev/v27.0/100539998049709/leadgen_forms' \
  -H 'Authorization: Bearer <page_access_token>' \
  -F name='Orçamento de gás' \
  -F questions='[{"type":"FULL_NAME"},{"type":"EMAIL"},{"type":"PHONE"},{"type":"CUSTOM","key":"botijoes","label":"Quantos botijões?"}]' \
  -F privacy_policy='{"url":"https://loja.example.com/privacidade","link_text":"Privacidade"}' \
  -F locale=pt_BR
# {"id":"100539998049736"}

With a user token, the response is (#210) A page access token is required to request this resource. In Mimicr, privacy_policy.url is required and CUSTOM questions need a label.

2. Create the ad

The campaign uses OUTCOME_LEADS, the ad set optimization_goal=LEAD_GENERATION, destination_type=ON_AD and promoted_object={"page_id":"…"}. The creative points to the form:

json
{
  "page_id": "100539998049709",
  "link_data": {
    "message": "Peça um orçamento",
    "link": "http://fb.me/",
    "call_to_action": { "type": "SIGN_UP", "value": { "lead_gen_form_id": "100539998049736" } }
  }
}

The form must belong to the same Page as the creative. The rest follows Create a campaign.

3. Subscribe to the webhook

There are two steps, and both are required. First the app subscribes to the page object on the leadgen field, with the app token:

bash
curl -s 'https://meta-ads.mimicr.dev/v27.0/<app_id>/subscriptions' \
  -H 'Authorization: Bearer <app_id>|<app_secret>' \
  -F object=page -F callback_url=https://app.example.com/meta/webhook \
  -F fields=leadgen -F verify_token=meu-token

Before answering, Mimicr verifies the callback the way Meta does: GET https://app.example.com/meta/webhook?hub.mode=subscribe&hub.challenge=<number>&hub.verify_token=meu-token. Your endpoint must answer 200 with the hub.challenge in the body; otherwise the subscription fails with 2200.

Then the Page installs the app, with the Page access token and pages_manage_metadata:

bash
curl -s 'https://meta-ads.mimicr.dev/v27.0/100539998049709/subscribed_apps' \
  -H 'Authorization: Bearer <page_access_token>' -F subscribed_fields=leadgen
# {"success":true}

Without the install on the Page, none of its leads generate a notification.

4. Receive the webhook

json
{
  "object": "page",
  "entry": [
    {
      "id": "100539998049709",
      "time": 1794028115,
      "changes": [
        {
          "field": "leadgen",
          "value": {
            "leadgen_id": "100539998049743",
            "page_id": "100539998049709",
            "form_id": "100539998049736",
            "adgroup_id": "120200539998049742",
            "ad_id": "120200539998049742",
            "created_time": 1794028115
          }
        }
      ]
    }
  ]
}
  • The POST carries X-Hub-Signature-256 (and the legacy X-Hub-Signature). Verify it before processing: Verify the signature.
  • adgroup_id is the old name of ad_id. Organic and test leads carry neither.
  • In Mimicr, ids come as strings. Meta's examples show numbers, but 15- to 18-digit ids don't fit safely in a JSON number. The leadgenNumericIds toggle sends numbers.
  • Answer 2xx within 10 s. Any other response is retried 30 s, 2 min, 10 min, 30 min, 1 h, 3 h, 6 h, 12 h, 24 h and 36 h after the first attempt; then the delivery becomes failed. Meta doesn't guarantee batching: Mimicr sends one change per POST.

5. Fetch the lead

The webhook only carries ids. Fetch the data with leads_retrieval:

bash
curl --url 'https://meta-ads.mimicr.dev/v27.0/100539998049743' \
  --header 'Authorization: Bearer <token>'
json
{
  "created_time": "2026-11-07T05:08:35+0000",
  "id": "100539998049743",
  "ad_id": "120200539998049742",
  "form_id": "100539998049736",
  "field_data": [
    { "name": "full_name", "values": ["Paulo Lead"] },
    { "name": "email", "values": ["paulo.lead@example.com"] },
    { "name": "phone_number", "values": ["+5511912345678"] },
    { "name": "botijoes", "values": ["Sim"] }
  ]
}

To list, use GET /{form_id}/leads or GET /{ad_id}/leads, with filtering=[{"field":"time_created","operator":"GREATER_THAN","value":<unix>}] to fetch only new ones. Without leads_retrieval, 200.

Generate leads in the sandbox

  • Test lead, like Meta's testing tool: POST /{form_id}/test_leads with the Page access token. Only one per form (the second answers 100/1892039); delete it with DELETE /{lead_id} to create another. It's organic, without ad_id, and fires the webhook.
  • Paid lead, as if someone filled in an ad's form: npx mimicr action meta-ads lead.submit ad_id=120200539998049742. It carries ad_id, counts in Insights (lead) and fires the webhook. With form_id instead of ad_id, the lead is organic. field_data accepts a JSON with full_name, email, phone_number; the rest is generated.
  • Automatic: with the autoLeads toggle, delivering lead ad sets generate real leads, up to 20 per hour.

To wait for the delivery in a test: npx mimicr wait meta-ads delivery field=leadgen ref=<lead_id> status=delivered.

Reference: Create form, Subscribe to app webhooks, Install the app on the Page, Get lead and Create test lead.