Developer guide

SMS webhooks: delivery reports, replies and payments

Instead of polling for message status, let JMSURF SMS call your server when something happens. This page lists every event, shows the payloads and explains signatures and retries.

Set up an endpoint

  1. In your workspace open Developers, then Webhooks, and add an HTTPS URL on a public host name (no IP addresses or custom ports).
  2. Copy the endpoint secret shown for it. Use it only on your server.
  3. Press Send test to receive a webhook.test event and check your handler.

Events

EventWhen it is sent
sms.queuedThe network accepted the message
sms.deliveredThe network confirmed delivery to the handset
sms.failedThe message failed; rejected messages are refunded
sms.unknownThe outcome is uncertain; it will be reconciled, do not resend
sms.inboundSomeone replied or texted your shortcode
payment.completedA 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.

sms.delivered
{
  "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"
}
sms.inbound
{
  "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"
}
payment.completed
{
  "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.

Node.js
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));
}
PHP
$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].

Make every message count.

Start with a free workspace. Add your audience, top up with M-Pesa and keep your customers in the conversation.

Create your workspace