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.

CallDirectionWhenRequired
Lead inAdPilot → CRMA new lead arrivesYes
Outcome backCRM → AdPilotThe lead's outcome, notes or follow-up date changes in the CRMOptional, recommended

Two secrets are involved:

SecretMade byUsed for
Workspace keyYour CRM. The customer pastes it into AdPilot.AdPilot sends it with every lead and signs the lead with it.
Reply keyAdPilot. 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

  1. 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 example https://crm.example.com/adpilot/leads/<random-token>/.
  2. 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.
  3. A place to store AdPilot's lead id (for example meta-1532) on the CRM lead. It is how duplicates are detected and how the lead is named in the outcome call.
  4. 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:

  1. In the CRM, copy the lead address and workspace key.
  2. 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.
  3. 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/"
  }
}
FieldNotes
idAdPilot'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.
testtrue 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, emailAny of them can be an empty string. The phone number is as the person typed it; it is not normalised.
lead.answersEvery other form answer, in form order. Questions differ from form to form.
lead.received_atWhen the person sent the form (ISO 8601 with offset).
lead.status, notes, follow_up_on, follow_up_timeWhat AdPilot holds when sending. Usually NEW, empty and null; they can be set when an older lead is sent by hand.
source.platformmeta or google.
source, Meta leadscampaign, campaign_id, ad.
source, Google leadsform (lead form name), account (Google Ads customer id), gclid. There is no campaign name.
adpilot.urlThe 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

  1. Find the workspace from the address. Unknown: answer 404.
  2. Compare the Authorization header with Bearer {workspace key}. Wrong: answer 401.
  3. Check X-AdPilot-Signature against the raw body bytes, before parsing. Wrong: answer 401.
  4. If "test": true, answer 200 and create nothing.
  5. If a lead with this id already exists in the workspace, answer 200 with that lead (or 409). Do not create a second one.
  6. Otherwise create the lead and answer 200.
  7. Do slow work such as assignment and notifications after answering.

Response

AnswerAdPilot treats it as
Any 2xxDelivered.
409Delivered, 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": trueThe same as 409.
401 or 403Failed: "The CRM refused the key". Retried.
Anything else, a timeout or no connectionFailed. 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"
}
FieldRequiredNotes
idYesThe id AdPilot sent with the lead.
statusNoOne of the six values below.
notesNoText, up to 5,000 characters. It replaces AdPilot's notes for the lead, so send the full current text.
follow_up_onNoYYYY-MM-DD, or null to clear it. Clearing it also clears the time.
follow_up_timeNoTime 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.

ValueMeaningReported to Meta
NEWNot contacted yetNo
CONTACTEDSpoken to, outcome not known yetNo
QUALIFIEDA good lead: real, reachable and interestedYes, as "Qualified"
CONVERTEDBecame a customerYes, as "Converted"
NOT_INTERESTEDReal person, not interestedNo
JUNKWrong number, fake or spamNo

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.

StatuserrorMeaning
401bad_keyReply key missing or wrong. Do not retry until it is fixed.
404unknown_leadNo lead with that id in the AdPilot account the key belongs to. Do not retry.
400bad_json, bad_status, bad_notes, bad_date, nothing_to_changeThe request is wrong. Do not retry.
5xx or no answerRetry 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

Limits in version 1

Questions: verifiedenquiry@gmail.com