Webhooks & Status Codes
Webhooks push events into your application: a delivery report for every SMS that reaches Safaricom or Airtel, every message a customer texts to your shortcode, premium SMS subscriber events and confirmed payments. This page covers how to set them up, how to prove a request came from Sozuri, the exact bytes you receive, and the status codes the send API returns.
- Types of webhooks
- Registering a callback URL
- Anatomy of a webhook request
- Verifying authenticity
- Testing your endpoint
- Status codes (synchronous)
- Response envelope per channel
- Delivery reports (asynchronous)
- SMS delivery webhook
- Inbound SMS webhook
- WhatsApp webhooks
- Premium SMS callbacks
- Mapping statuses
Types of webhooks
| Webhook | Fires when… | Where you set the URL |
|---|---|---|
| SMS delivery report | Safaricom or Airtel reports the final outcome of an SMS you sent. See SMS delivery webhook. | Manage API › Callback URLs › Delivery reports |
| Inbound SMS | A customer texts your shortcode. See Inbound SMS webhook and 2-way SMS. | Manage API › Callback URLs › Inbox |
| A customer messages your WhatsApp number, or WhatsApp reports what happened to a message you sent. See WhatsApp webhooks. | Your project’s WhatsApp page | |
| Premium SMS | A subscriber activates, deactivates or gives consent, an on-demand request arrives, or a premium message gets its delivery report. See Premium SMS callbacks. | The callback URL on the premium offer |
| Payment | An M-Pesa payment to your paybill (STK Push or paybill/C2B) is confirmed. Failed payments send nothing. See payments. | Your paybill’s payment settings |
Registering a callback URL
- Open your project dashboard.
- Go to Manage API › Callback URLs and press Create Webhooks (or Modify if you already have one).
- Paste your endpoints into Inbound Messages Callback URL and Delivery Status Callback URL. Either field can hold several URLs separated by commas; every URL in the list receives every event.
- Tick Enforce HTTPS if you want plain
http://URLs refused (recommended). - Save. Saving creates your Auth Key and signing secret (see Verifying authenticity) and runs a test against each saved URL (see Testing your endpoint). The next real event goes to your endpoint.
POST with a JSON body and no session or Authorization header, and answer with a 2xx within 8 seconds (4 to connect). Only a 2xx counts as received; whatever you put in the response body is ignored. Webhooks are not retried, so keep your receiver available and idempotent. Give us the final URL: we do not follow redirects, and a redirect counts as a failed webhook. Every webhook URL must be on the public internet: we check its address each time we send, and never send to localhost or a private network address, even if it was public when you saved it.
Anatomy of a webhook request
- Method — always
POST - Headers —
Content-Type: application/json,Accept: application/jsonandX-Sozuri-Signature(see below) - Body — one line of compact JSON (no spaces or line breaks). Keys always arrive in the order shown on this page. Forward slashes are not escaped; any non-ASCII character (an accent, an emoji) arrives as a
\uescape. - authKey — the last key of every body: your Auth Key, for the simple authenticity check
- messageId — on a delivery report, the same
messageIdthe send API returned for that recipient - timestamp — Unix time in seconds at which Sozuri sent this webhook. It is not the time the handset received the message.
Verifying authenticity
Every SMS delivery report, inbound SMS, premium SMS and WhatsApp webhook carries two independent proofs that it came from us. Both are created when you first save your callback configuration — find them under Manage API › Callback URLs › Webhook security, where you can also reveal, copy and rotate them.
- Auth Key — sent in the body of every request as
authKey. It starts withszk_. The simplest check: compare it to your stored copy. - Signing secret — never sent. It starts with
szs_and keys theX-Sozuri-Signatureheader, an HMAC-SHA256 over the exact request body.
Either check is enough on its own. The signature is the stronger one: the Auth Key travels in the request body, so it can be replayed and it ends up in whatever logs and proxies sit in front of your endpoint. The signature covers a timestamp, so a captured request cannot be replayed later, and it stays trustworthy even if your Auth Key leaks.
authKey and without the header. Payment webhooks are not signed at all: they carry neither.
Signature header
X-Sozuri-Signature: t=1760000000,v1=9a7f4061677b6b83573e75426ddce37e04fe66145652ac08f3ef2d1b95db5307
- Split the header into
t(Unix seconds when we signed) andv1(64 lowercase hex characters). The header has no spaces. - Build the signed string:
t, then a full stop, then the raw request body, byte for byte. - Compute
hex(hmac_sha256(key = signing_secret, message = signed_string)). The key is your signing secret exactly as shown, including theszs_prefix; it is not hex-decoded. - Compare your result with
v1using a constant-time comparison, and reject atmore than 5 minutes (300 seconds) from your own clock.
crypto.timingSafeEqual, hash_equals), not ==.
Node.js (Express)
const crypto = require('crypto');
// Keep the raw bytes: the signature covers them, not the parsed object.
app.use(express.json({ verify: (req, res, buf) => { req.rawBody = buf; } }));
function fromSozuri(req) {
// Simple: the Auth Key check
// return req.body.authKey === process.env.SOZURI_AUTH_KEY;
// Stronger: the signature over the RAW body
const m = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(req.get('X-Sozuri-Signature') || '');
if (!m) return false;
if (Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false; // replay guard
const expected = crypto.createHmac('sha256', process.env.SOZURI_SIGNING_SECRET)
.update(m[1] + '.')
.update(req.rawBody)
.digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(m[2]));
}
PHP
$raw = file_get_contents('php://input');
$header = $_SERVER['HTTP_X_SOZURI_SIGNATURE'] ?? '';
if (!preg_match('/^t=(\d+),v1=([0-9a-f]{64})$/', $header, $m) || abs(time() - (int) $m[1]) > 300) {
http_response_code(401);
exit;
}
$expected = hash_hmac('sha256', $m[1] . '.' . $raw, getenv('SOZURI_SIGNING_SECRET'));
if (!hash_equals($expected, $m[2])) {
http_response_code(401);
exit;
}
$event = json_decode($raw, true); // safe to process
Check your code against this example
With the signing secret szs_000000000000000000000000000000000000000000000000 (szs_ followed by 48 zeros), this exact body:
{"project":"your_project","messageId":"0123456789abcdef0123456789abcdef01234567","channel":"sms","status":"success","network":"safaricom","type":"bulkDelivery","timestamp":1760000000,"authKey":"szk_000000000000000000000000000000000000"}
signed at t=1760000000 gives v1=9a7f4061677b6b83573e75426ddce37e04fe66145652ac08f3ef2d1b95db5307. Your verifier must accept it (ignoring the age check, since the time is in the past) and reject it if a single byte of the body changes.
http:// URL is refused when you save it, and we will not send a webhook to one: it is skipped, not downgraded. It covers every webhook signed with these credentials. Recommended: your Auth Key is in the request body, so an https:// URL keeps it off the wire in plain text.
Testing your endpoint
Under Manage API › Callback URLs, Test DLR sends one real, signed delivery report to your delivery URL and Test Inbox sends one inbound message to your inbox URL. The create and Modify forms have a Test this URL now button, and saving under Modify tests both saved fields. You see the request we sent and the response you gave.
- Same request as the real thing — same headers, same signature, same keys in the same order, plus
"test": truejust beforeauthKey. ThemessageIdstarts withsozuri_test_. Check either and skip the event, so a test never books a delivery or a reply against a message that does not exist. - Every URL in the field is tested, up to the first 5.
- Redirects are not followed. A
3xxanswer is a failed test; enter the final URL. - Public addresses only. A URL that is not publicly reachable (
localhost, a private network address) is not sent a test. - A test of a saved delivery URL sets its status — see pausing. A test of the inbox URL only updates the status shown on the page; inbound messages are forwarded whatever it says.
Test DLR body
{"project":"your_project","messageId":"sozuri_test_0011223344556677","channel":"sms","status":"success","network":"safaricom","type":"bulkDelivery","timestamp":1760000000,"test":true,"authKey":"szk_000000000000000000000000000000000000"}
Test Inbox body
{"project":"your_project","number":"254700000000","shortcode":"20000","message":"This is a Sozuri webhook test. No real message was received.","messageId":"sozuri_test_0011223344556677","channel":"interactive","status":"success","network":"safaricom","type":"interactive","timestamp":1760000000,"test":true,"authKey":"szk_000000000000000000000000000000000000"}
The sozuri_test_ id ends in 16 random hex characters, and the timestamp is the time of the test.
Status codes (synchronous)
When you send SMS, every recipient comes back in recipients[] with a statusCode (a string) and a status. The values differ between /v1/messaging, whose response is frozen for existing integrations, and /v2/messaging. Delivery reports never carry a statusCode; their status values are listed under SMS delivery webhook.
| Code | /v1/messaging status |
/v2/messaging status |
Meaning |
|---|---|---|---|
| 11 | sent | accepted | Accepted and queued for sending. On /v1/messaging this is also the answer for a scheduled message. |
| 12 | unsupported_number | unsupported_number | The number is too short to be a Kenyan mobile number. Not sent, not charged. |
| 14 | — | scheduled | Accepted for sending at your sendAt time. |
| 24 | sender_not_registered | sender_not_registered | Your sender ID is not registered for this message type on the recipient’s network. Not sent, not charged. |
A full-length number on a network we do not deliver to is answered 11, then fails without being charged; its final status is in your SMS log. Premium SMS sends answer accepted / 11. Errors that stop the whole request (an unknown project, not enough balance, no sender ID) do not use these codes: they come back as a message, see below.
Response envelope per channel
Each channel wraps success and error responses differently. The table tells you which fields to read; each channel’s own page lists its errors.
| Channel | Success envelope | Error envelope | Full error list |
|---|---|---|---|
| SMS | messageData.messages, recipients[] |
messageData.message, beginning Error., with HTTP 200 |
SMS errors |
status and the message id (exact body on each WhatsApp page) |
error.code, error.message, error.status, with a 4xx or 5xx HTTP status |
WhatsApp · Official WhatsApp | |
| Premium SMS (on-demand) | messageData.messages, recipients[] |
status ("error") + description |
Premium on-demand errors |
| Premium SMS (subscription) | messageData.messages, recipients[] |
status ("error") + description |
Subscription errors |
| Airtime | Not currently available | HTTP 503 with data.status ("unavailable") + data.message |
Airtime errors |
Sample success response (SMS, /v2/messaging)
{
"messageData": { "messages": 1 },
"recipients": [
{
"messageId": "0123456789abcdef0123456789abcdef01234567",
"to": "254700000001",
"status": "accepted",
"statusCode": "11",
"bulkId": "bulk0000000000000a.000000001760000000",
"messagePart": 1,
"type": "promotional"
}
]
}
The same object from /v1/messaging says "status": "sent". messagePart is the number of 160-character parts; type is the message type you sent.
Sample error response (SMS)
{
"messageData": {
"message": "Error. Insufficient balance. Top up and try again."
}
}
Delivery reports (asynchronous)
After an SMS reaches Safaricom or Airtel, the network reports whether it was delivered, and Sozuri POSTs that outcome to your Delivery Status Callback URL. One report per message: only the final outcome is sent, never an interim stage.
- Match reports to your records by
messageId. Reports arrive in whatever order the networks send them, and the same report can occasionally arrive twice, so apply them idempotently and ignore amessageIdyou don’t recognise. - Authenticate every report. Check the
authKeyin the body or theX-Sozuri-Signatureheader (see Verifying authenticity) before you act on it. - Only messages that reached a network get a report. A message that failed before it left Sozuri (an unsupported number, an unregistered sender ID, a refused send) produces no webhook; its outcome is in the send response and your SMS log. Telkom sends no delivery reports at all (see below).
- No automatic retries. If your endpoint returns anything other than a 2xx, or does not answer within 8 seconds, the report is not sent again. The delivery status is still recorded in your dashboard.
- A failing URL is paused. If a delivery URL fails 50 times in a row (any response other than 2xx, a timeout, or a refused connection) and is still failing 10 minutes after the first of those failures, we pause it and email the project owner. While it is paused we send it nothing; delivery statuses are still recorded in your dashboard, and reports that arrive while it is paused are not sent later. A single successful delivery resets the count. Each URL in a comma-separated list is paused on its own, so a dead URL never silences a healthy one. Only delivery URLs are paused; inbound and premium webhooks are not.
- A test sets the status straight away. Pressing Test DLR on a saved URL (or saving it under Modify, which runs the same test) updates its status at once: a 2xx keeps it, or makes it, active; any other answer, or no answer, pauses it immediately, with no email, so we stop sending it delivery reports until a test passes. A URL we refuse to contact (see Testing your endpoint) keeps its status.
- Resuming a paused URL. Fix the endpoint, then press Test DLR: a 2xx resumes it immediately. We also send the same test to each paused URL every hour and resume it automatically when it answers 2xx. Active URLs are never sent tests.
SMS delivery webhook
The same shape for Safaricom and Airtel: the only differences are network and the values of status. These are the exact bytes we send (the signature is computed with the example secret from Verifying authenticity).
Safaricom
POST https://example.com/sozuri/delivery HTTP/1.1
Content-Type: application/json
Accept: application/json
X-Sozuri-Signature: t=1760000000,v1=9a7f4061677b6b83573e75426ddce37e04fe66145652ac08f3ef2d1b95db5307
{"project":"your_project","messageId":"0123456789abcdef0123456789abcdef01234567","channel":"sms","status":"success","network":"safaricom","type":"bulkDelivery","timestamp":1760000000,"authKey":"szk_000000000000000000000000000000000000"}
Airtel
POST https://example.com/sozuri/delivery HTTP/1.1
Content-Type: application/json
Accept: application/json
X-Sozuri-Signature: t=1760000000,v1=79f11eb859336a23f6d7a9b1e181637dca5740bd0e94152c3473721165c0d6cf
{"project":"your_project","messageId":"0123456789abcdef0123456789abcdef01234567","channel":"sms","status":"failed","network":"airtel","type":"bulkDelivery","timestamp":1760000000,"authKey":"szk_000000000000000000000000000000000000"}
| Field | Type | Description |
|---|---|---|
project | String | Your project name. |
messageId | String | The messageId the send API returned for this recipient (40 hex characters). |
channel | String | Always sms. |
status | String | The outcome; see the tables below. |
network | String | safaricom or airtel. |
type | String | Always bulkDelivery. |
timestamp | Integer | Unix seconds when we sent this webhook. |
authKey | String | Your Auth Key. |
Safaricom status values
Safaricom’s numeric delivery code is mapped to one of five strings before it reaches your webhook.
status | Carrier codes (input) | Meaning |
|---|---|---|
success | 0 | Delivered to the recipient’s phone. |
network_failure | 1001 | A network error on the carrier side. |
delivery_impossible | 1, 5, 11, 13, 21, 31, 32, 34, 99 | Cannot be delivered: barred number, incompatible handset, blocked content and similar. |
absent_subscriber | 6, 27 | The phone was unreachable (off, or out of coverage). |
unknown_error | anything else | The network reported a failure we have no specific mapping for. Treat it as not delivered. |
Airtel status values
Airtel reports are reduced to two values. Airtel’s interim “submitted” stage is never forwarded; you get one webhook, with the final outcome.
status | Meaning |
|---|---|
success | Delivered to the recipient’s phone. |
failed | Airtel could not deliver it (absent subscriber, expired, rejected, or any other failure). |
Telkom
Telkom does not send delivery reports, so no delivery webhook is ever sent for a Telkom number. A Telkom message’s final status is whether Telkom accepted it: your SMS log shows Sent when it was accepted, and Failed when Telkom refused it. Sent does not mean the phone received it.
Inbound SMS webhook
When a customer texts your shortcode on Safaricom or Airtel, we POST the message to your Inbound Messages Callback URL, signed like every other webhook:
POST https://example.com/sozuri/inbox HTTP/1.1
Content-Type: application/json
Accept: application/json
X-Sozuri-Signature: t=1760000000,v1=dbaa9251658685d80ea04011aaa7e53cf001e7ce4f1ea30e5bb038dd6dde4c55
{"project":"your_project","number":"254700000001","shortcode":"20000","message":"BALANCE","messageId":"89abcdef0123456789abcdef0123456789abcdef","channel":"interactive","status":"success","network":"safaricom","type":"interactive","timestamp":1760000000,"authKey":"szk_000000000000000000000000000000000000"}
| Field | Type | Description |
|---|---|---|
project | String | Your project name. |
number | String | The customer who sent the message. |
shortcode | String | Your shortcode they sent it to. |
message | String | The text they sent. |
messageId | String | Sozuri’s id for this inbound message (40 hex characters). |
channel | String | Always interactive. |
status | String | Always success. |
network | String | safaricom or airtel. |
type | String | Always interactive. |
timestamp | Integer | Unix seconds when we sent this webhook. |
authKey | String | Your Auth Key. |
Inbound webhooks are not retried and are never paused. Once an hour we also send a HEAD request to each inbox URL; it only sets the reachability shown on the Callback URLs page, and any answer below 500 counts as reachable.
WhatsApp webhooks
WhatsApp does not use the delivery URL above. Messages your customers send, and the delivery and read receipts for messages you send, go to the webhook URL set on your project’s WhatsApp page, signed with the same Auth Key and signing secret. Their bodies and status values are on the WhatsApp pages:
- WhatsApp: receiving messages and delivery & read receipts
- Official WhatsApp: receiving messages and delivery & read receipts
Premium SMS callbacks
Premium SMS events go to the callback URL set on the premium offer (comma-separated URLs are each sent the event). They are signed with your project’s Auth Key and signing secret, refuse a plain http:// URL when Enforce HTTPS is ticked, time out after 8 seconds, do not follow redirects, and are not retried or paused. The type field tells you which event it is:
type | When it fires | status |
|---|---|---|
activation | A subscriber’s subscription became active. | active |
deactivation | A subscriber unsubscribed. | inactive |
consent | The subscriber answered the network’s consent prompt. | active if they accepted, inactive if they declined |
linkNotification | An on-demand request arrived. Carries the linkId you must quote in your reply. | The text the subscriber sent |
premiumDelivery | The delivery report for a premium message you sent. | The network’s own delivery wording |
Full bodies: subscription webhooks and on-demand webhooks.
Mapping statuses
Your SMS log and dashboard show one set of statuses for every network. This table maps the status you receive onto them, with the WhatsApp receipt values alongside:
| Dashboard status | SMS — Safaricom | SMS — Airtel | WhatsApp receipt |
|---|---|---|---|
| Delivered | success | success | delivered, read |
| Undelivered | network_failure, delivery_impossible, absent_subscriber, unknown_error | failed | — |
| Sent (with the network, no report yet) | No webhook yet. A Telkom message stays here. | sent | |
| Failed (never left Sozuri, or refused) | No webhook; see the send response or your SMS log. | failed | |
Use cases
The most common ways teams put webhooks and status codes to work.
Mark an order as paid
When the payment webhook arrives, match its BillRefNumber to your invoice, flip the order to paid and trigger fulfilment automatically.
Idempotent delivery receivers
Key your handler on messageId and apply changes idempotently. A duplicate report, or a test with "test": true, becomes harmless by construction.
Real-time delivery dashboard
Stream reports into your warehouse and chart delivery rate, network breakdown and failure reasons by hour. The network field gives you Safaricom vs Airtel splits for free.
Smart retries
Decide per reason: absent_subscriber and network_failure may succeed if you send again later; delivery_impossible will not.
Wire Sozuri into your stack.
Configure a callback URL on your project, press Test DLR, and watch a signed webhook arrive at your endpoint.