Set up an endpoint
- In your workspace open Developers, then Webhooks, and add an HTTPS URL on a public host name (no IP addresses or custom ports).
- Copy the endpoint secret shown for it. Use it only on your server.
- Press Send test to receive a webhook.test event and check your handler.
Events
| Event | When it is sent |
|---|---|
| sms.queued | The network accepted the message |
| sms.delivered | The network confirmed delivery to the handset |
| sms.failed | The message failed; rejected messages are refunded |
| sms.unknown | The outcome is uncertain; it will be reconciled, do not resend |
| sms.inbound | Someone replied or texted your shortcode |
| payment.completed | A wallet top-up was confirmed |
Request format
Every webhook is a POST with Content-Type application/json and three headers: x-jmsurf-event (the event name), x-jmsurf-event-id (unique per delivery, use it to ignore repeats) and x-jmsurf-signature.
{
"id": "4e1c…",
"event": "sms.delivered",
"data": {
"message_id": "2b0d7c1e-…",
"reference": "8f6241c0-24df-4ce2-b39b-9ef85eab198f",
"recipient": "+2547XXXXXXXX",
"status": "delivered",
"provider": "…",
"cost_kes": 0.4,
"occurred_at": "2026-11-23T07:15:02Z"
},
"created_at": "2026-11-23T07:15:03Z"
}{
"id": "9a7d…",
"event": "sms.inbound",
"data": {
"inbound_id": "…",
"from": "+2547XXXXXXXX",
"to": "<your shortcode>",
"keyword": "INFO",
"message": "INFO opening hours",
"received_at": "2026-11-23T07:20:00Z"
},
"created_at": "2026-11-23T07:20:01Z"
}{
"id": "…",
"event": "payment.completed",
"data": { "topup_id": "…", "amount_kes": 500, "receipt": "<M-Pesa receipt>", "status": "completed", "occurred_at": "…" },
"created_at": "…"
}Verify the signature
x-jmsurf-signature is sha256= followed by the hex HMAC-SHA256 of the raw request body, using your endpoint secret as the key. Compute it over the exact bytes you received (before parsing JSON) and compare in constant time. Reject anything that does not match.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(rawBody, header, secret) {
const expected = "sha256=" + createHmac("sha256", secret).update(rawBody).digest("hex");
return header?.length === expected.length && timingSafeEqual(Buffer.from(header), Buffer.from(expected));
}$ok = hash_equals('sha256=' . hash_hmac('sha256', $raw, $secret), $_SERVER['HTTP_X_JMSURF_SIGNATURE'] ?? '');Retries and timeouts
- Answer with any 2xx status within 8 seconds. Do slow work after responding.
- Any other answer or a timeout is retried with exponential backoff (about 2, 4, 8, 16 minutes) up to five attempts.
- Events can arrive more than once and out of order. Use x-jmsurf-event-id to ignore repeats and the status order queued, then delivered or failed, to keep the final state.
Polling instead
If you cannot receive webhooks, poll GET /api/v1/sms/{id} or list recent messages with GET /api/v1/messages?status=…&reference=… (scope sms:read). Page with before set to the last created_at you received.
Start sending today
Create a free workspace, top up with M-Pesa and send your first message at KES 0.40 per SMS. Questions first? Call or WhatsApp +254 712 504 593 or email [email protected].
Related pages
- API referenceEvery endpoint, request and response of the REST API.
- Delivery reportsLive SMS delivery reports for Safaricom, Airtel and Telkom: delivered, failed and pending counts, failure reasons, refunds for rejected messages and CSV export.
- SMS API in Node.jsSend SMS from Node.js with fetch and the JMSURF SMS API: single and bulk sends, idempotent retries and an Express webhook with HMAC signature check.
- Two-way SMSReceive SMS replies in a shared inbox, answer in one click and automate keywords like JOIN, INFO and STOP. Two-way SMS for Kenyan businesses with webhooks.