Webhooks
Instagram webhooks in Unipile's payloads: messaging events, account status events (signed out, security check, suspended), registering, delivery, retries and signatures.
Early access. Tell us what you're building and we'll set you up. Contact us
Lempile calls your address when something happens on an Instagram account:
messaging:message_received,message_read,message_reaction.account_status: the account was connected, signed out, stopped by a security check, suspended, reconnected or removed (below).
A webhook belongs to the workspace of the key that registered it.
Register A Webhook#
curl -sS -X POST "https://api.lempile.com/api/v1/webhooks" \
-H "X-API-KEY: $LEMPILE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_url": "https://hooks.example.com/instagram",
"name": "inbox",
"source": "messaging",
"events": ["message_received", "message_reaction"],
"account_ids": ["00000000-0000-4000-8000-0000000000c1"],
"headers": [{ "key": "X-Team", "value": "support" }]
}'201:
{ "object": "WebhookCreated", "webhook_id": "8c0b6a7e-3f52-4d1e-9a40-2b7c5d9e1f03", "secret": "whsec_…" }| Field | |
|---|---|
request_url |
An https:// address on the public internet (no IP address, localhost or internal name). |
source |
messaging or account_status. |
events |
The events to send. A messaging webhook without events gets message_received only, as on Unipile. Unipile's message_edited, message_deleted and message_delivered are accepted, but Instagram accounts never send them. |
account_ids |
messaging only: up to 50 of the workspace's Instagram accounts, by their Lempile id (as GET /accounts shows it). Without it, every Instagram account of the workspace. |
format |
messaging only: json (the default) or form (a form body: each value as text, objects as JSON, empty values left out). |
data |
messaging only: up to 40 { key, name }. The payload then holds only these keys, each under its new name. |
enabled |
messaging only: false registers it switched off. Default true. |
name |
Your name for it, sent as webhook_name. |
headers |
Up to 10 { key, value } headers added to every call. |
secret signs every call (below). It's shown this once: store it.
GET /webhooks lists the workspace's webhooks, header values masked. A
messaging one also shows account_ids (each { id, name, type }), format,
data and type: "AUTO". DELETE /webhooks/{webhook_id} removes one
(WebhookDeleted).
messaging webhooks here are for Instagram accounts; LinkedIn's are on
Lempile Direct.
Messaging Events#
{
"account_id": "00000000-0000-4000-8000-0000000000c1",
"account_type": "INSTAGRAM",
"account_info": { "feature": "classic", "type": "INSTAGRAM", "user_id": "61234567890" },
"event": "message_received",
"chat_id": "340282366841710301244276026398105347911",
"timestamp": "2026-11-25T17:41:07.000Z",
"webhook_name": "inbox",
"message_id": "340282366841710301244276026398105347911_cAAAAB3xYz9wQkLmNo",
"message": "See you at 10?",
"sender": {
"attendee_id": "48210937561",
"attendee_name": "Sam Example",
"attendee_provider_id": "48210937561",
"attendee_profile_url": "https://www.instagram.com/sam.example/",
"attendee_public_identifier": null,
"attendee_specifics": { "provider": "INSTAGRAM" }
},
"attendees": [
{
"attendee_id": "48210937561",
"attendee_name": "Sam Example",
"attendee_provider_id": "48210937561",
"attendee_profile_url": "https://www.instagram.com/sam.example/",
"attendee_public_identifier": null,
"attendee_specifics": { "provider": "INSTAGRAM" }
}
],
"attachments": [],
"is_sender": false,
"subject": null,
"provider_chat_id": "340282366841710301244276026398105347911",
"provider_message_id": "cAAAAB3xYz9wQkLmNo",
"is_event": 0,
"chat_pinned": 0,
"quoted": null,
"reply_to": null,
"is_forwarded": null,
"is_view_once": null,
"chat_content_type": null,
"message_type": "MESSAGE",
"is_group": false,
"folder": [],
"event_type": null
}- Ids are the API's:
chat_idandmessage_idwork as they are inGET /chats/{chat_id}andGET /messages/{message_id}.provider_message_idis Instagram's message id alone. - The account's own messages arrive as
message_receivedtoo, as on Unipile, withis_sender: true(sender.attendee_provider_idis thenaccount_info.user_id). message_readaddsread_by(who saw it).message_reactionaddsreactionandreaction_sender.attachments: each{ attachment_id, attachment_type, attachment_size, attachment_unavailable, attachment_url }, as Unipile's webhooks send them.- Messages from before the account was connected never arrive as events.
- An event is sent once per webhook, even when Instagram's inbox is read again. Once it's delivered, Lempile keeps its ids, not the message's text.
When They Arrive#
Instagram's web app tells nobody about a new message, so each account's own browser reads its inbox about every 10 minutes (each account at its own times), and not between 23:00 and 07:00 in the account's own time zone. An event arrives up to about 10 minutes after the message; a message sent at night arrives in the morning. Reading the inbox opens no conversation, so it never shows anyone "Seen".
Account Status Events#
An account_status webhook (source: "account_status") reports every account
of the workspace, Instagram's included: one call each time an account's status
changes. Register it with events to get only some (Unipile's names, such as
credentials or creation_success, or Lempile's, such as
account.status.disconnected); without events, it gets all of them.
{
"event": "account.status.disconnected",
"account_id": "00000000-0000-4000-8000-0000000000c1",
"account_type": "INSTAGRAM",
"status": "disconnected",
"previous_status": "running",
"reason": "restricted",
"occurred_at": "2026-11-29T11:39:12.000Z",
"AccountStatus": {
"account_id": "00000000-0000-4000-8000-0000000000c1",
"account_type": "INSTAGRAM",
"message": "CREDENTIALS"
}
}AccountStatus is Unipile's own object, unchanged; the fields above it are
Lempile's. X-Lempile-Event repeats event.
| What happened | status / reason |
AccountStatus.message |
What to do |
|---|---|---|---|
| The account was connected | running / connected |
CREATION_SUCCESS |
|
| It was connected again | running / reconnected |
RECONNECTED |
|
| Lempile cleared a suspension, and the account still works | running / recovered |
OK |
|
| A sign-in started | connecting / signing_in |
CONNECTING |
|
| A sign-in failed | disconnected / signin_failed |
CREDENTIALS |
Connect it again. |
| Instagram signed it out | disconnected / signed_out |
CREDENTIALS |
Connect it again. |
| Instagram asks for a security check | disconnected / checkpoint |
CREDENTIALS |
Open the account on Instagram, then connect it again. |
| Instagram suspended or disabled it | disconnected / restricted |
CREDENTIALS |
See below. |
| It was removed from Lempile | deleted / deleted |
DELETED |
Lempile sees what Instagram shows the next time it opens the account: one of your calls, or the account's inbox read (about every 10 minutes, not between 23:00 and 07:00 in the account's time zone). A change at night reaches you in the morning. Lempile never opens an account only to check its status.
Suspended accounts. When Instagram shows its "suspended" or "disabled"
page, Lempile marks the account restricted and keeps it so until a person
clears it: every call on it answers 403 errors/account_restricted, and a new
sign-in is refused. Appeal on Instagram; once Instagram gives the account back,
write to support@lempile.com. Lempile then clears it, and the webhook gets
running / recovered, or disconnected / signed_out when Instagram also
signed the account out (connect it again; it keeps its account_id).
Nothing recovers an Instagram account by itself: unlike LinkedIn accounts,
there's no automatic retry, and no degraded or errored status. A signed-out
account stays disconnected until someone connects it again.
GET /accounts/{id} shows the same thing at any time, without opening the
account's browser: sources[].status (OK, CONNECTING, CREDENTIALS,
ERROR), and lifecycle with the status and reason above
(Accounts).
Delivery#
- Lempile sends a
POST: JSON, or a form withformat: "form". Answer with a2xx. - No answer, a
5xx,408,425or429: the event is sent again 30 seconds, 2 minutes, 10 minutes, 30 minutes and 2 hours later (six tries in all), then given up. Any other answer stops it. A redirect is never followed.
Check A Call Came From Lempile#
Each call carries
X-Lempile-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256 of "<t>.<body>">,
made with the webhook's secret:
import { createHmac, timingSafeEqual } from "node:crypto";
function fromLempile(header, rawBody, secret) {
const { t, v1 } = Object.fromEntries(header.split(",").map((part) => part.split("=")));
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
return fresh && expected.length === v1.length && timingSafeEqual(Buffer.from(expected), Buffer.from(v1));
}Check it on the raw body, before parsing it. Refuse a call more than 5 minutes old: someone may be sending an old one again.
Was this page helpful?