Connect your CRM to AdPilot
For developers · format version 1 · last updated 3 October 2026
AdPilot can pass every new lead from Google, Facebook and Instagram ads to a CRM as it arrives, and take back what happened with the lead. This page says what a CRM has to build for that to work. Any CRM that can receive an HTTPS request can do it.
Summary
There are two calls, both HTTPS and JSON, one in each direction.
| Call | Direction | When | Required |
|---|---|---|---|
| Lead in | AdPilot → CRM | A new lead arrives | Yes |
| Outcome back | CRM → AdPilot | The lead's outcome, notes or follow-up date changes in the CRM | Optional, recommended |
Two secrets are involved:
| Secret | Made by | Used for |
|---|---|---|
| Workspace key | Your CRM. The customer pastes it into AdPilot. | AdPilot sends it with every lead and signs the lead with it. |
| Reply key | AdPilot. Shown on Leads → Send leads to CRM; the customer pastes it into the CRM. | The CRM sends it with every outcome. |
One AdPilot account can send to several addresses: the customer adds one workspace per business and chooses which lead forms and campaigns go to each. If your CRM has workspaces, teams or tenants, give each its own address and key. Each workspace gets its own reply key in AdPilot, and that key only works for leads sent to that workspace.
What to build
- A lead address and a workspace key for each workspace, shown where the customer can copy them. The address must be
https://on the public internet, for examplehttps://crm.example.com/adpilot/leads/<random-token>/. - The endpoint behind that address, which checks the key and signature, ignores test leads, never creates the same lead twice, and creates the lead. See Lead in.
- A place to store AdPilot's lead
id(for examplemeta-1532) on the CRM lead. It is how duplicates are detected and how the lead is named in the outcome call. - Optional: a field for the reply key, and a call to AdPilot whenever the lead changes. See Outcome back.
The customer then connects in this order:
- In the CRM, copy the lead address and workspace key.
- In AdPilot, open Leads → Send leads to CRM, paste both and click Connect. AdPilot sends a test lead and saves the connection only if the CRM answers 2xx.
- On the same AdPilot page, copy Reply key and paste it into the CRM's reply key field.
1. Lead in (AdPilot → CRM)
Request
POST {lead address}
Content-Type: application/json
Authorization: Bearer {workspace key}
X-AdPilot-Signature: sha256={hex HMAC-SHA256 of the raw body, keyed with the workspace key}
X-AdPilot-Event: lead.created
Idempotency-Key: {same value as "id" in the body}
User-Agent: AdPilot/1
AdPilot does not follow redirects and waits 10 seconds for the answer.
Body
{
"event": "lead.created",
"version": 1,
"id": "meta-1532",
"test": false,
"sent_at": "2026-10-03T16:20:11.512+00:00",
"lead": {
"name": "Meena Shah",
"phone": "9822222222",
"email": "meena@example.com",
"answers": [
{"question": "Course", "answer": "BSc"},
{"question": "City", "answer": "Pune"}
],
"received_at": "2026-10-03T16:20:05+00:00",
"status": "NEW",
"notes": "",
"follow_up_on": null,
"follow_up_time": null
},
"source": {
"platform": "meta",
"platform_name": "Facebook & Instagram",
"platform_lead_id": "1203948573920",
"campaign": "Admissions 2026",
"campaign_id": "120210000000000",
"ad": "Ad A"
},
"adpilot": {
"url": "https://ads.verifiedenquiries.com/meta/leads/1532/"
}
}
| Field | Notes |
|---|---|
id | AdPilot's reference for the lead: meta-<number> or google-<number>. Stable and unique within the AdPilot account. Use it to detect duplicates and keep it for the outcome call. |
test | true for the test lead sent when the customer connects or clicks "Send a test lead". Its id starts with test-. Answer 2xx but do not create a lead. |
lead.name, phone, email | Any of them can be an empty string. The phone number is as the person typed it; it is not normalised. |
lead.answers | Every other form answer, in form order. Questions differ from form to form. |
lead.received_at | When the person sent the form (ISO 8601 with offset). |
lead.status, notes, follow_up_on, follow_up_time | What AdPilot holds when sending. Usually NEW, empty and null; they can be set when an older lead is sent by hand. |
source.platform | meta or google. |
source, Meta leads | campaign, campaign_id, ad. |
source, Google leads | form (lead form name), account (Google Ads customer id), gclid. There is no campaign name. |
adpilot.url | The lead in AdPilot, for a "View in AdPilot" link. Opening it needs an AdPilot login. |
Fields may be added later without changing version. Ignore fields you do not know.
What the endpoint must do, in order
- Find the workspace from the address. Unknown: answer 404.
- Compare the
Authorizationheader withBearer {workspace key}. Wrong: answer 401. - Check
X-AdPilot-Signatureagainst the raw body bytes, before parsing. Wrong: answer 401. - If
"test": true, answer 200 and create nothing. - If a lead with this
idalready exists in the workspace, answer 200 with that lead (or 409). Do not create a second one. - Otherwise create the lead and answer 200.
- Do slow work such as assignment and notifications after answering.
Response
| Answer | AdPilot treats it as |
|---|---|
| Any 2xx | Delivered. |
| 409 | Delivered, and marked Duplicate in AdPilot: the CRM already has this person (for example the same phone number) and added nothing. AdPilot does not retry. If the body gives the existing lead's id and url, AdPilot links to it. |
2xx, 400 or 422 with "duplicate": true | The same as 409. |
| 401 or 403 | Failed: "The CRM refused the key". Retried. |
| Anything else, a timeout or no connection | Failed. Retried. |
A 2xx body may be empty. If it is JSON with these optional fields, AdPilot uses them:
{"id": "L-20931", "url": "https://crm.example.com/leads/20931"}
url (it must start with https://) becomes the Open in CRM button on the lead in AdPilot. id is stored for reference.
Retries and duplicates
AdPilot sends within seconds of the lead arriving, tries again after 15 seconds, then once an hour, up to 30 attempts. The customer can also press "Send again", or "Resync with CRM" on a campaign's leads to send all of them again after some were deleted in the CRM. So the same lead can arrive more than once, for example when the CRM saved it but the answer was lost. That is why step 5 above matters.
Example endpoint (Python, Django)
An illustration, not a library. Workspace, Lead and AdPilotLink stand for your own models.
import hashlib, hmac, json
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
@csrf_exempt
@require_POST
def adpilot_lead(request, token):
link = AdPilotLink.objects.select_related("workspace").filter(token=token).first()
if link is None:
return JsonResponse({"ok": False, "error": "unknown_workspace"}, status=404)
raw = request.body
if not hmac.compare_digest(request.headers.get("Authorization", ""), f"Bearer {link.key}"):
return JsonResponse({"ok": False, "error": "bad_key"}, status=401)
expected = "sha256=" + hmac.new(link.key.encode(), raw, hashlib.sha256).hexdigest()
if not hmac.compare_digest(request.headers.get("X-AdPilot-Signature", ""), expected):
return JsonResponse({"ok": False, "error": "bad_signature"}, status=401)
data = json.loads(raw)
if data.get("test"):
return JsonResponse({"ok": True, "test": True}) # nothing is created
person, source = data["lead"], data["source"]
lead, created = Lead.objects.get_or_create(
workspace=link.workspace, adpilot_id=data["id"], # unique together: no duplicates
defaults={"name": person["name"], "phone": person["phone"], "email": person["email"],
"answers": person["answers"], "source_platform": source["platform_name"],
"source_campaign": source.get("campaign") or source.get("form", ""),
"source_ad": source.get("ad", ""), "adpilot_url": data["adpilot"]["url"]})
return JsonResponse({"ok": True, "id": str(lead.pk),
"url": request.build_absolute_uri(lead.get_absolute_url())})
2. Outcome back (CRM → AdPilot)
Call this when a lead that came from AdPilot changes outcome, notes or follow-up date in the CRM. It keeps AdPilot's lead list in step with the CRM. For Facebook and Instagram leads it does more: a good outcome is reported to Meta, which is how Meta learns to find better leads. So send outcomes as they change, not in a nightly batch.
Request
POST https://ads.verifiedenquiries.com/crm/outcome/
Content-Type: application/json
Authorization: Bearer {reply key}
{
"id": "meta-1532",
"status": "QUALIFIED",
"notes": "Wants the weekend batch. Call back Monday.",
"follow_up_on": "2026-10-12",
"follow_up_time": "15:30"
}
| Field | Required | Notes |
|---|---|---|
id | Yes | The id AdPilot sent with the lead. |
status | No | One of the six values below. |
notes | No | Text, up to 5,000 characters. It replaces AdPilot's notes for the lead, so send the full current text. |
follow_up_on | No | YYYY-MM-DD, or null to clear it. Clearing it also clears the time. |
follow_up_time | No | Time of day for the follow-up, HH:MM in 24-hour form, or null. Needs a follow_up_on date. |
Send at least one of status, notes, follow_up_on and follow_up_time. Fields left out are not changed.
Status values
Map your CRM's own stages onto these six. A stage with no sensible match is simply not sent.
| Value | Meaning | Reported to Meta |
|---|---|---|
NEW | Not contacted yet | No |
CONTACTED | Spoken to, outcome not known yet | No |
QUALIFIED | A good lead: real, reachable and interested | Yes, as "Qualified" |
CONVERTED | Became a customer | Yes, as "Converted" |
NOT_INTERESTED | Real person, not interested | No |
JUNK | Wrong number, fake or spam | No |
Response
Success, 200:
{"ok": true, "id": "meta-1532", "status": "QUALIFIED", "follow_up_on": "2026-10-12", "follow_up_time": "15:30", "meta_told": true}
meta_told is true when Meta was told on this call; false when it should have been but could not be (no Meta dataset is chosen in AdPilot, or Meta returned an error); and null when there was nothing to tell (a Google lead, a status that is not reported, or one already reported). The lead is saved in all three cases.
| Status | error | Meaning |
|---|---|---|
| 401 | bad_key | Reply key missing or wrong. Do not retry until it is fixed. |
| 404 | unknown_lead | No lead with that id in the AdPilot account the key belongs to. Do not retry. |
| 400 | bad_json, bad_status, bad_notes, bad_date, nothing_to_change | The request is wrong. Do not retry. |
| 5xx or no answer | Retry later. The call is safe to repeat. |
Error bodies look like {"ok": false, "error": "bad_status", "message": "…"}.
Testing
# What AdPilot sends to the CRM (signature left out)
curl -X POST "$LEAD_ADDRESS" \
-H "Authorization: Bearer $WORKSPACE_KEY" -H "Content-Type: application/json" \
-d '{"event":"lead.created","version":1,"id":"test-1a2b3c4d","test":true,"lead":{"name":"Test Lead","phone":"+919800000000","email":"test@example.com","answers":[]},"source":{"platform":"meta","platform_name":"Facebook & Instagram"},"adpilot":{"url":"https://ads.verifiedenquiries.com/leads/"}}'
# What the CRM sends to AdPilot
curl -X POST https://ads.verifiedenquiries.com/crm/outcome/ \
-H "Authorization: Bearer $REPLY_KEY" -H "Content-Type: application/json" \
-d '{"id":"meta-1532","status":"QUALIFIED"}'
From AdPilot's Leads → Send leads to CRM page you can send a test lead at any time, see every lead the CRM has not accepted and why, and see when the last outcome arrived. To send a real lead without waiting for one, open any lead in AdPilot and click Send to CRM.
Done when
- Clicking Connect in AdPilot succeeds and no lead appears in the CRM.
- A wrong workspace key gives "The CRM refused the key" in AdPilot.
- Send to CRM on an AdPilot lead creates one CRM lead with name, phone, email, answers and source.
- Send again for the same lead does not create a second CRM lead.
- Open in CRM on the AdPilot lead opens the right CRM lead.
- Changing the stage in the CRM changes the outcome on the lead in AdPilot within seconds.
Limits in version 1
- AdPilot does not tell the CRM when someone changes a lead's outcome inside AdPilot.
- Leads from before the connection was made are sent only by hand, from each lead's page.
- ChatGPT and Pinterest campaigns have no lead forms, so they send nothing.
Questions: verifiedenquiry@gmail.com