# Connect lead sources

[`POST /leads/ingest`](reference#ingestLeads) accepts one structure, the one in [Send leads into KLCT](send-leads), and refuses fields it does not define. A tool that sends its own payload shape (a form builder's webhook, an ad platform) therefore cannot be pointed at it directly. Put a step in between that builds our structure. Zapier and Make do this without code.

Before any of these, **send a test with `"dry_run": true`**: the call is validated and nothing is saved.

## What every recipe sends

One lead per call, with its fields at the top level:

```json
{
  "vendor": "Facebook Lead Ads",
  "lead_source": "meta_ads",
  "list_name": "Facebook leads",
  "campaign": "<campaign name from the trigger>",
  "email": "<email>",
  "phone": "<phone>",
  "name": "<first name>",
  "last_name": "<last name>",
  "external_id": "<the lead's id in the source>",
  "source_url": "<the form or page, if the trigger has it>"
}
```

Map only these fields. Anything else you want to keep goes under `"metadata": { "budget": "…" }` as flat text values. Use `lead_source` `meta_ads` or `google_ads` only for leads that really came from those ads: a verdict on them is reported back to the platform.

Headers on every call: `Authorization: Bearer <your API key>` and `Content-Type: application/json`. Use the source's own lead id as the `Idempotency-Key` so a Zap or scenario that runs twice does not enrol anyone twice.

## Zapier

1. **Trigger:** the app the leads come from, for example *Facebook Lead Ads → New Lead*, *Typeform → New Entry* or *Google Forms → New Response*.
2. **Action:** *Webhooks by Zapier → Custom Request*.
   - Method `POST`, URL `https://app.klctai.com/api/leads/ingest`.
   - Data: the JSON above, with each `<…>` replaced by a field from the trigger.
   - Headers: `Authorization` with `Bearer` and your key, `Content-Type: application/json`, and `Idempotency-Key` set to the trigger's lead id.
3. Test the step. A `200` with `created` or `updated` means it worked; a `422` lists what to fix under `issues`.

## Make

1. **Trigger module:** for example *Facebook Lead Ads → Watch Leads*, or the form tool's own module.
2. **Action module:** *HTTP → Make a request*.
   - URL `https://app.klctai.com/api/leads/ingest`, method `POST`.
   - Headers: `Authorization: Bearer <your key>` and `Idempotency-Key: <lead id>`.
   - Body type *Raw*, content type *JSON (application/json)*, request content: the JSON above with the trigger's fields mapped in.
   - Turn on *Parse response* so later modules can read `created`, `updated` and `errors`.
3. Run once and check the response. Add an error handler on the module so a `429` is retried after the `Retry-After` wait.

## Facebook Lead Ads

Facebook does not send leads to a URL of your choosing, so connect it through Zapier or Make as above. Use `vendor` `Facebook Lead Ads`, `lead_source` `meta_ads`, and put the campaign or ad-set name in `campaign` so each lead's arrival record says which one produced it. If the sheet that Facebook's connector fills is already in Google Sheets, you can use **Integrations → Google Sheets leads** instead: no API key is needed.

## Form tools and any other webhook

Typeform, Google Forms, Jotform, Webflow, a landing page and similar tools can all call a webhook, but their payload is their own. Either route them through Zapier or Make as above, or receive their webhook on your own server, rebuild the payload in our structure and call the API from there (the [script examples](send-leads) show how). Send the `consent` object with the wording and time the person agreed, if the form collected it.

## When a lead is refused

The response tells you exactly why: `errors[].issues` names the field and gives a code such as `unknown_field` (a field we do not define), `missing_contact_point` (no email or phone) or `reserved_key` (a `metadata` key KLCT uses itself). Fix the mapping and send again. See [`GET /leads/ingests`](reference#listLeadIngests) for the history of what was sent and refused.