Receive events
Get a webhook for each incoming message, such as an iMessage, and each send's result, or read the same events on one open stream
A send answers 202 the moment Mapier queues it. Everything after that (the
send's result, a person's reply, a read receipt) arrives as an event. You get
events in one of two ways, and both carry the same facts.
| You want | Use |
|---|---|
| Events as they happen, on a connection you hold open | GET /v1/response_stream |
| Events posted to your own server | A webhook endpoint, made on the console's Webhooks page |
| What happened before you were listening | GET /v1/events |
Event types lists every event.
Open the stream
The stream is server-sent events over HTTPS, so you can watch it with curl.
-N shows each event as it arrives.
curl -N https://api.mapier.ai/v1/response_stream \
-H "Authorization: Bearer $MAPIER_API_KEY" \
-H "x-mapier-version: 2026-12-01" \
-H "Accept: text/event-stream": connected
id: 0192a7c4-6a02-7e11-8c4d-2b9f7e3a5d10
event: message
data: {"conversationId":"a0000000-0000-4000-8000-000000000001","from":"+14155550100","text":"Is my table ready?","messageId":"0192a7c4-6a02-7e11-8c4d-2b9f7e3a5d22","lineId":"0192a7b0-3e4f-7051-8c6d-7e8f9a0b1c2d"}
: pingLines that start with : are not events. : connected says the stream is open,
and : ping arrives every 25 seconds to keep it open.
Two events are always on the stream: message, a person writing to your line,
and command, the result of a command you sent. Add more with ?events=, for
example ?events=receipts,reactions:
events= | Adds |
|---|---|
receipts | A message was delivered or read |
delivery_failures | A message was not delivered |
reactions | A reaction was added or removed |
moderation | A person edited or unsent a message |
polls | A poll was created, changed or voted on |
locations | A person shared their location |
conversations | A conversation started, or a group changed |
chat_backgrounds | A conversation's background changed |
gaps | Some of a line's messages may be missing for a while |
message.received | Incoming messages in the webhook's shape |
On some channels, some options add nothing:
| Channel | Adds nothing |
|---|---|
| iMessage | — |
?channel=, ?conversationId= and ?lineId= narrow the stream to one channel,
conversation or line. New event names can appear at any time: ignore a name you
do not know, and keep the stream open.
Reconnect without missing anything
The connection drops now and then, even when all is well. Reconnect in a loop,
and send the id: of the last event you handled as Last-Event-ID. The stream
sends what you missed, up to 90 days back, then carries on.
- Save each event's
idonce you have handled it, somewhere that survives a restart. - When the stream ends, wait a few seconds. Each key may connect 10 times a minute.
- Reconnect with
Last-Event-IDset to the savedid. - Handle events by
id, so one that arrives twice is handled once.
A stream that ends with an error event is different: your key or project
stopped working, and reconnecting will not help.
If Mapier missed some of a line's messages for a while, a line.gap event says
so, after every message it recovered has reached you.
Receive webhooks
A webhook endpoint gets each event as an HTTPS POST. Make one on the
console's Webhooks page and pick the event types it gets, or with a
personal access token through
POST /v1/webhook-endpoints.
POST /your/endpoint HTTP/1.1
content-type: application/json
mapier-event-id: 0192a7c4-6a02-7e11-8c4d-2b9f7e3a5d10
mapier-timestamp: 1789378800
mapier-signature: v1=6f1a…
{
"id": "0192a7c4-6a02-7e11-8c4d-2b9f7e3a5d10",
"type": "message.received",
"environment": "live",
"occurredAt": "2026-09-14T09:24:31.000Z",
"deliveryId": "0192a7c5-1b2c-7d3e-8f4a-5b6c7d8e9f01",
"attempt": 1,
"data": {
"conversationId": "a0000000-0000-4000-8000-000000000001",
"from": "+14155550100",
"text": "Is my table ready?",
"lineId": "0192a7b0-3e4f-7051-8c6d-7e8f9a0b1c2d"
}
}- Check the signature before you read the body. Mapier signs
"${timestamp}.${body}"with HMAC-SHA256, using your endpoint's whole signing secret,whsec_included. - Refuse a
mapier-timestampmore than 300 seconds from your clock. - Accept the request if any
v1=entry matches. While you rotate a secret, the header carries two for 24 hours. - Store the event, then answer
2xx. Do the work after. - Skip an event whose
idyou already stored. An event can arrive more than once, and every attempt carries the sameid.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyWebhookSignature(input: {
secret: string; // the endpoint's whole signing secret, `whsec_` included
body: string | Uint8Array; // the raw request body, exactly as received
timestamp: string | null | undefined; // the mapier-timestamp header
signature: string | null | undefined; // the mapier-signature header
toleranceSeconds?: number;
}): boolean {
// Return false, never throw: every input but the secret comes from the
// sender, and a throw becomes a 500 that the sender retries.
const { secret, body, timestamp, signature } = input;
if (!secret || typeof timestamp !== "string" || typeof signature !== "string") return false;
if (!/^\d{1,15}$/.test(timestamp)) return false;
const tolerance = input.toleranceSeconds ?? 300;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > tolerance) return false;
const expected = Buffer.from(
createHmac("sha256", secret).update(`${timestamp}.`).update(body).digest("hex"),
"utf8"
);
return signature
.split(",")
.map((entry) => entry.trim())
.filter((entry) => entry.startsWith("v1="))
.some((entry) => {
// Compare the lower-cased hex text as bytes; never decode it, because
// `Buffer.from(value, "hex")` stops silently at the first non-hex
// character. Compare lengths in bytes, because `timingSafeEqual` throws
// on buffers of different lengths, and non-ASCII text is longer in bytes.
const presented = Buffer.from(entry.slice(3).toLowerCase(), "utf8");
return presented.length === expected.length && timingSafeEqual(presented, expected);
});
}Some iMessage lines, on older software, report a chat background change as a
message.received with no text. Skip a received message that has no text and
no attachment rather than reply to it.
When your endpoint does not answer
Each attempt has ten seconds to get a 2xx. Anything else is tried again, 12
attempts over just under three days: after 10 seconds, 1 minute, 5 minutes, 30
minutes, 2 hours, 6 hours, then every 12 hours. After the last, the console
shows the delivery as Gave up, and Retry now sends it once more. A
redirect counts as a failure.
The event is kept for at least 90 days whatever happens, so you can still read
it with GET /v1/events. The console's Events page shows
every event, and Inspect shows each delivery of it.
Some event types reach an endpoint only when you select them by name: a person's
location, their edits and unsends, polls, group changes and chat backgrounds
(conversation.background_changed, the stream's chat_background).
Select all leaves them out.