Tracking
Webhooks
Receive signed delivery reports and campaign events on your own endpoint.
Setup#
In Dashboard → API → Webhooks, add an HTTPS URL and choose events. The signing secret is shown once when you create the endpoint.
Events#
message.delivered: a message reached the handset.message.failed: a message ended as failed, rejected, expired or cancelled.campaign.completed: a campaign finished sending.
Payload#
{
"id": "d2c1b9e0-...",
"event": "message.delivered",
"created_at": "2026-09-30T08:15:10.002Z",
"data": {
"message_id": "5b0f2c7e-7a55-4b1e-9d0a-3c1d2e4f6a70",
"to": "+8801XXXXXXXXX",
"status": "delivered",
"error_code": null,
"segments": 1,
"cost": "0.35",
"refunded": false,
"client_reference": "order-10234",
"campaign_id": null,
"occurred_at": "2026-09-30T08:15:09.771Z"
}
}Verifying signatures#
Each request carries X-SMSFlow-Signature: t=<unix seconds>,v1=<hex>, where v1 is HMAC-SHA256 of t + "." + raw body using your endpoint secret. Compute it over the raw bytes, compare in constant time, and reject timestamps older than 5 minutes.
import crypto from "node:crypto";
// Express: use the raw body, not the parsed JSON, when computing the signature.
app.post("/webhooks/sms", express.raw({ type: "application/json" }), (req, res) => {
const header = req.get("X-SMSFlow-Signature") ?? ""; // "t=1727683200,v1=5d41..."
const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
const expected = crypto
.createHmac("sha256", process.env.MZSMS_WEBHOOK_SECRET)
.update(`${t}.${req.body}`)
.digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(t)) < 300;
if (!fresh || !crypto.timingSafeEqual(Buffer.from(v1 ?? ""), Buffer.from(expected))) {
return res.status(400).send("invalid signature");
}
const event = JSON.parse(req.body);
// Deduplicate on event.id: the same delivery can be retried.
res.sendStatus(200);
});Retries and ordering#
Respond with a 2xx status within 10 seconds. Otherwise we retry with exponential backoff for up to 8 attempts. Events can arrive more than once and out of order: deduplicate on id and use data.occurred_at for ordering.