Guides
Lead Sync and webhook
Create lead forms, subscribe to notifications with the HMAC challenge, receive LEAD_ACTION, read the lead, retries and re-validation.
Lead Sync brings the leads of LinkedIn's forms (Lead Gen Forms) into your CRM: you create the form, link it to the creative through leadgenCallToAction, subscribe a webhook, and for each lead LinkedIn sends a short POST with the lead URN. Your server fetches the full lead through the API.
1. Create the form
curl -si https://linkedin-ads.mimicr.dev/rest/leadForms \
--header 'Authorization: Bearer <token>' --header 'LinkedIn-Version: 202610' --header 'X-Restli-Protocol-Version: 2.0.0' \
--header 'Content-Type: application/json' \
--data '{
"owner": { "sponsoredAccount": "urn:li:sponsoredAccount:521119150" },
"name": "Orçamento de gás",
"creationLocale": { "country": "BR", "language": "pt" },
"hiddenFields": [ { "name": "utm_source", "value": "linkedin" } ],
"content": {
"headline": { "localized": { "pt_BR": "Peça um orçamento" } },
"questions": [
{ "name": "first_name", "question": { "localized": { "pt_BR": "Nome" } }, "predefinedField": "FIRST_NAME", "questionDetails": { "textQuestionDetails": { "maxResponseLength": 300 } } },
{ "name": "email", "question": { "localized": { "pt_BR": "E-mail" } }, "predefinedField": "EMAIL", "questionDetails": { "textQuestionDetails": { "maxResponseLength": 300 } } },
{ "name": "company", "question": { "localized": { "pt_BR": "Empresa" } }, "predefinedField": "COMPANY_NAME", "questionDetails": { "textQuestionDetails": { "maxResponseLength": 300 } } }
],
"legalInfo": { "privacyPolicyUrl": "https://example.com.br/privacidade", "legalDisclaimer": { "localized": { "pt_BR": "Ao enviar, você concorda." } } }
},
"state": "PUBLISHED"
}'
# 201, x-restli-id: 6700000002689218625- At least one question; multiple choice with 2 to 15 options; text from 1 to 300;
predefinedFieldprefills with member data (23 values, such asFIRST_NAME,EMAIL,COMPANY_NAME,JOB_TITLE). - Repeated question names or option ids: 409 "The Lead Form has duplicate name."
statePUBLISHEDstarts the form review (reviewInfo.reviewStatusPENDING, thenAUTO_APPROVEDafter 10 sandbox minutes). Until then, linked creatives getFORM_HOLD.[reprovar]in the name rejects it.- Once published, the form only accepts changes to the headline, description, legal disclaimer, URLs, thank-you content and
state; changing the questions creates a new version.PUBLISHED → ARCHIVEDputs the creatives onFORM_HOLD.
Leads point at the version: urn:li:versionedLeadGenForm:(urn:li:leadGenForm:6700000002689218625,1).
2. Answer the challenge
Before creating the subscription, LinkedIn calls your URL:
GET https://crm.example.com/li/leads?secret=abc&challengeCode=4d6c1f0e-9b0a-4f52-a8e8-2f1c3b7d9e10
The endpoint has 3 seconds to answer 200 with Content-Type: application/json:
{ "challengeCode": "4d6c1f0e-9b0a-4f52-a8e8-2f1c3b7d9e10", "challengeResponse": "<hex HMAC-SHA256 of the challengeCode, with the client secret>" }import { createHmac } from "node:crypto";
app.get("/li/leads", (req, res) => {
if (req.query.secret !== process.env.WEBHOOK_SECRET) return res.sendStatus(401);
const challengeCode = String(req.query.challengeCode);
const challengeResponse = createHmac("sha256", process.env.LINKEDIN_CLIENT_SECRET).update(challengeCode).digest("hex");
res.json({ challengeCode, challengeResponse });
});3. Subscribe to notifications
curl -si https://linkedin-ads.mimicr.dev/rest/leadNotifications \
--header 'Authorization: Bearer <token>' --header 'LinkedIn-Version: 202610' --header 'X-Restli-Protocol-Version: 2.0.0' \
--header 'Content-Type: application/json' \
--data '{
"webhook": "https://crm.example.com/li/leads?secret=abc",
"owner": { "sponsoredAccount": "urn:li:sponsoredAccount:521119150" },
"leadType": "SPONSORED"
}'
# 201, x-restli-id: 718690If the challenge fails, the answer is 400 "This URL did not pass the security challenge check" and nothing is created. Rules:
- HTTPS only. LinkedIn sends no authentication headers: a secret in the query string is the documented way to protect the endpoint. Mimicr also accepts
httponlocalhost(or withallowHttpWebhooks). versionedFormandassociatedEntity(optional) filter by form version and creative; a form of another owner answers 400.- Needs
r_marketing_leadgen_automationandCREATIVE_MANAGERor higher on the account: aVIEWERgets 403. - Up to 1,500 subscriptions per owner and lead type. Only
SPONSOREDis simulated; other types answer 501.
The URL is re-validated every 2 sandbox hours. After 3 consecutive failures, the webhook is blocked and stops getting leads (deliveries become skipped_blocked). The webhook.challenge action re-validates right away, and webhook.unblock unblocks it.
4. Receive the LEAD_ACTION
POST https://crm.example.com/li/leads?secret=abc Content-Type: application/json X-LI-Signature: c01243d72fcb01033df3b211d9fed8e024f3bc75f831ccfaa6f6cf48ff893ba3
{
"type": "LEAD_ACTION",
"leadGenFormResponse": "urn:li:leadGenFormResponse:4aa37137-8262-48cb-9736-964d6cf642fe-2",
"leadGenForm": "urn:li:versionedLeadGenForm:(urn:li:leadGenForm:6700000002689218625,1)",
"owner": { "sponsoredAccount": "urn:li:sponsoredAccount:521119150" },
"associatedEntity": { "associatedCreative": "urn:li:sponsoredCreative:166531097" },
"leadType": "SPONSORED",
"leadAction": "CREATED",
"occurredAt": 1793950472864
}leadAction is CREATED or DELETED (the member deleted the lead). occurredAt is epoch milliseconds (the docs' sample shows another format; Mimicr sends valid, compact JSON). Check the signature first: Verify the signature. Every subscription matching the owner and type gets the POST.
Answer 2xx quickly. Any other answer, or 5 seconds without one, is a failure. LinkedIn documents no retries; Mimicr retries 1 min, 5 min, 30 min, 2 h and 6 h after the first attempt and then gives up. LinkedIn may deliver the same notification twice: dedupe on leadGenFormResponse + occurredAt.
5. Read the lead
The id is the part of the URN after urn:li:leadGenFormResponse::
curl -s 'https://linkedin-ads.mimicr.dev/rest/leadFormResponses/4aa37137-8262-48cb-9736-964d6cf642fe-2?fields=id,leadType,owner,submitter,submittedAt,formResponse,ownerInfo,leadMetadataInfo' \ --header 'Authorization: Bearer <token>' --header 'LinkedIn-Version: 202610' --header 'X-Restli-Protocol-Version: 2.0.0'
{
"id": "4aa37137-8262-48cb-9736-964d6cf642fe-2",
"leadType": "SPONSORED",
"owner": { "sponsoredAccount": "urn:li:sponsoredAccount:521119150" },
"submitter": "urn:li:person:1XillZ_J09",
"submittedAt": 1793950472829,
"formResponse": {
"answers": [
{ "questionId": 8556988801, "answerDetails": { "textQuestionAnswer": { "answer": "Camila" } } },
{ "questionId": 5894337558, "answerDetails": { "textQuestionAnswer": { "answer": "camila.lima55@example.com.br" } } },
{ "questionId": 6656398810, "answerDetails": { "textQuestionAnswer": { "answer": "Gás Bom Ltda" } } }
],
"consentResponses": []
},
"ownerInfo": { "sponsoredAccountInfo": { "name": "Conta Principal" } },
"leadMetadataInfo": { "sponsoredLeadMetadataInfo": { "campaign": { "id": 347365458, "name": "Gás para empresas", "type": "SPONSORED_UPDATES" } } }
}Answers come by questionId; match them with the questions of the form. Reading leads needs r_marketing_leadgen_automation and a role on the account and on the account's organization; without it, 401 "The member doesn't have lead access permission." (the campaign_manager persona hits this). A deleted lead answers 404.
To backfill or reconcile, use list leads with q=owner&owner=(sponsoredAccount:urn%3Ali%3AsponsoredAccount%3A521119150)&leadType=(leadType:SPONSORED) and, optionally, submittedAtTimeRange=(start:{ms},end:{ms}).
Generating leads in the sandbox
npx mimicr action linkedin-ads lead.submit creative=urn:li:sponsoredCreative:166531097 npx mimicr action linkedin-ads lead.submit form=6700000002689218625 test=true npx mimicr action linkedin-ads lead.delete lead=4aa37137-8262-48cb-9736-964d6cf642fe-2 npx mimicr wait linkedin-ads delivery action=CREATED status=delivered
The submitter is a synthetic Brazilian member (name, @example.com.br email, +55… phone, company), unless you pass member and answers. Test leads (test=true) have no campaign or creative and match limitedToTestLeads=true; guest=true makes a lead without submitter. With the autoLeads toggle, the modelled delivery of lead campaigns also turns into real leads, with webhooks.