Developers
API and integrations
How to integrate your system with Ledio.ai: report new sign-ups and conversions, send messages and verification codes on WhatsApp, and receive events back by webhook.
Ledio integrates with your system in both directions. You tell Ledio when something happens on your side (someone signed up, someone bought) and Ledio tells you when something happens in the conversation (a new contact showed up, a contact became a customer).
All endpoints start from https://api.ledio.ai and accept and return JSON.
Every call needs two headers. Both are generated in the dashboard, under Settings → API and webhooks.
| Field | Type | Description |
|---|---|---|
x-api-keyrequired | string | Identifies your business in Ledio. It's visible in the dashboard and can be copied from there. |
x-webhook-secretrequired | string | The integration secret, starts with whsec_. It's shown only once, when you generate it. Ledio stores only a hash, so there's no way to recover it later: if you lose it, generate a new one. |
These headers authorize any request on behalf of your business. Keep them on the server. Never put them in frontend code, a mobile app or a public repository: anyone who has both can send messages from your WhatsApp.
If either is missing or wrong, the response is 401 with a message saying which one failed.
Endpoints respond 200 with the same shape. Always check the success field: a 200 with success: false means we authenticated you, but the action didn't happen (number not on WhatsApp, contact not found, channel disconnected).
{
"success": true,
"message": "Welcome message sent",
"contactId": "1f5c2a10-2b3c-4d5e-6f70-8a9b0c1d2e3f"
}| Field | Type | Description |
|---|---|---|
success | boolean | Whether the action was completed. |
message | string | Details of what happened, or the reason when success is false. |
contactId | string | The contact's id in Ledio, when the action involved one. Store it to match records with your system. |
/webhook/external/new-userTells Ledio that someone signed up in your system. Ledio creates the contact, checks whether the number exists on WhatsApp and, if it does, the AI agent starts the conversation in the chosen flow.
| Field | Type | Description |
|---|---|---|
phonerequired | string | Phone number with country code, digits only: 5511999999999. No spaces, parentheses or dashes. |
name | string | The person's name. The agent uses it to personalize the conversation. |
externalId | string | Their id in your system. Lets you match both sides later. |
flow | CONVERSIONSUPPORTONBOARDINGBILLINGFEEDBACKCUSTOM | How the agent should approach them. Defaults to CONVERSION (sales focus). |
context | object | Free-form data the agent will know during the conversation: source, campaign, intended plan. |
curl -X POST https://api.ledio.ai/webhook/external/new-user \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-webhook-secret: whsec_YOUR_SECRET" \
-d '{
"phone": "5511999999999",
"name": "John Smith",
"externalId": "usr_abc123",
"flow": "CONVERSION",
"context": { "source": "landing_page", "campaign": "black_friday" }
}'/webhook/external/user-convertedTells Ledio that the person subscribed or bought. The agent stops selling and starts treating them as a customer. Send this as soon as the payment is confirmed: without it, the agent keeps offering what they already bought.
| Field | Type | Description |
|---|---|---|
phonerequired | string | The same phone number used at sign-up. |
name | string | Updates the contact's name, if it already exists. |
externalId | string | The person's id in your system. |
context | object | What they bought, so the agent has context: { "plan": "pro", "value": 2990, "currency": "BRL" }. |
curl -X POST https://api.ledio.ai/webhook/external/user-converted \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-webhook-secret: whsec_YOUR_SECRET" \
-d '{
"phone": "5511999999999",
"context": { "plan": "pro", "value": 2990, "currency": "BRL" }
}'/webhook/external/change-flowChanges how the agent behaves with an existing contact. Useful when the person opens a support request in your system and you want the WhatsApp conversation to follow along.
| Field | Type | Description |
|---|---|---|
phonerequired | string | The contact's phone number. |
flowrequired | CONVERSIONSUPPORTONBOARDINGBILLINGFEEDBACKCUSTOM | The new flow. |
context | object | Reason for the change: { "reason": "user_requested_support", "ticket_id": "TK-123" }. |
curl -X POST https://api.ledio.ai/webhook/external/change-flow \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-webhook-secret: whsec_YOUR_SECRET" \
-d '{ "phone": "5511999999999", "flow": "SUPPORT" }'/webhook/external/send-messageSends a text over WhatsApp to a contact who has already talked to you.
This endpoint doesn't create contacts and doesn't send to anyone who has never talked to you. That's a deliberate safeguard: messaging cold numbers is the fastest way to get your business's WhatsApp banned. To start a conversation from scratch, use the new sign-up endpoint.
| Field | Type | Description |
|---|---|---|
phonerequired | string | Phone number of an existing contact. |
message | string | The text to send. |
context | string | Information for the agent to take into account from now on. E.g.: "Lead came from Instagram, interested in a 2024 SUV". |
curl -X POST https://api.ledio.ai/webhook/external/send-message \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-webhook-secret: whsec_YOUR_SECRET" \
-d '{
"phone": "5511999999999",
"message": "Hi! How can I help?"
}'/webhook/external/otpSends a verification code over WhatsApp using an authentication template approved by Meta.
Requires your business to be on Meta's Cloud API and to have an approved authentication template. If you connect by QR code, this endpoint doesn't work. Talk to support before integrating.
| Field | Type | Description |
|---|---|---|
phonerequired | string | Destination phone number. |
coderequired | string | The code you generated. Ledio only delivers it; it doesn't generate or validate it. |
expiresInMinutesrequired | number | How many minutes the code is valid, shown in the message. |
name | string | Recipient's name. |
externalId | string | The person's id in your system. |
brand | string | Brand name shown in the message. |
curl -X POST https://api.ledio.ai/webhook/external/otp \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-H "x-webhook-secret: whsec_YOUR_SECRET" \
-d '{
"phone": "5511999999999",
"code": "123456",
"expiresInMinutes": 5
}'The other direction. Register a URL under Settings → API and webhooks and Ledio sends a POST to it when something happens in the conversation.
| Event | Type | Description |
|---|---|---|
contact.created | event | A new contact started a conversation. |
contact.converted | event | A contact was marked as a customer, by the agent, from the dashboard or through the conversion endpoint. |
contact.updated | event | The agent reclassified the contact's interest (engagement) or found out their name. |
All events arrive in the same envelope:
{
"id": "5f1c2a10-2b3c-4d5e-6f70-8a9b0c1d2e3f",
"type": "contact.converted",
"createdAt": "2026-08-14T18:22:05.412Z",
"data": {
"businessSlug": "your-business",
"contactId": "1f5c2a10-2b3c-4d5e-6f70-8a9b0c1d2e3f",
"phone": "5511999999999",
"name": "John Smith",
"status": "CONVERTED",
"flow": "ONBOARDING",
"engagement": "HOT"
}
}Use the id to discard duplicates: if delivery fails, Ledio retries, so the same event may arrive twice. Make your handler idempotent.
Every request is signed in the x-ledio-signature header, in the format sha256=<hex>. It's an HMAC-SHA256 of the body exactly as received, using the secret you registered.
Compute the HMAC over the raw body, before any parsing. If you serialize the JSON again to verify it, the signature won't match: that's the most common mistake at this step.
import crypto from 'node:crypto'
// rawBody = the body as a string, unparsed
function signatureMatches(rawBody, header, secret) {
const expected =
'sha256=' +
crypto.createHmac('sha256', secret).update(rawBody).digest('hex')
const a = Buffer.from(expected)
const b = Buffer.from(header ?? '')
// Constant-time comparison avoids leaking the signature through timing
return a.length === b.length && crypto.timingSafeEqual(a, b)
}Respond with 2xx quickly. If your endpoint takes too long or returns an error, Ledio treats it as a failure and retries later.
| Code | Type | Description |
|---|---|---|
401 | authentication | Missing header, unknown API key or wrong secret. The message says which. |
400 | validation | Invalid body: a required field is missing or flow has a value outside the list. |
200 with success: false | business rule | Authenticated, but the action didn't happen. The reason comes in message: number not on WhatsApp, contact not found, channel disconnected. |
Store the contactId returned by the first call. It's the key for matching the Ledio conversation with the record in your system, and it saves you from relying on the phone number, which can change.
Always send the phone number in the same format, with country code and digits only. Ledio normalizes it, but sticking to one format on your side makes it easier to check when something doesn't match.
Treat success: false as an expected response, not an exception. A number that isn't on WhatsApp is common and shouldn't break your processing queue.
If something here doesn't match what you're seeing in practice, reach out through support in the dashboard. Docs that don't match the behavior are a bug, and we want to know.