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

WebhookFires 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
WhatsApp 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

  1. Open your project dashboard.
  2. Go to Manage API › Callback URLs and press Create Webhooks (or Modify if you already have one).
  3. 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.
  4. Tick Enforce HTTPS if you want plain http:// URLs refused (recommended).
  5. 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.
Your endpoint must accept a 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/json and X-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 \u escape.
  • authKey — the last key of every body: your Auth Key, for the simple authenticity check
  • messageId — on a delivery report, the same messageId the 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 with szk_. The simplest check: compare it to your stored copy.
  • Signing secret — never sent. It starts with szs_ and keys the X-Sozuri-Signature header, 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.

A project that has never saved a configuration under Callback URLs has no Auth Key or signing secret, so its premium SMS and WhatsApp webhooks arrive without authKey and without the header. Payment webhooks are not signed at all: they carry neither.
Signature header
X-Sozuri-Signature: t=1760000000,v1=9a7f4061677b6b83573e75426ddce37e04fe66145652ac08f3ef2d1b95db5307
  1. Split the header into t (Unix seconds when we signed) and v1 (64 lowercase hex characters). The header has no spaces.
  2. Build the signed string: t, then a full stop, then the raw request body, byte for byte.
  3. Compute hex(hmac_sha256(key = signing_secret, message = signed_string)). The key is your signing secret exactly as shown, including the szs_ prefix; it is not hex-decoded.
  4. Compare your result with v1 using a constant-time comparison, and reject a t more than 5 minutes (300 seconds) from your own clock.
Compute the HMAC over the raw request body, before any JSON parsing. Re-serialising the parsed object produces different bytes (spacing, escaping) and the signature will never match. Compare digests with a constant-time function (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.

Rotating. Rotate under Webhook security replaces both the Auth Key and the signing secret at once, and the very next webhook uses the new pair. Deploy the new values to your receiver first, or accept either value during the changeover, so no webhook is rejected while you switch.
Enforce HTTPS. With this ticked, a plain 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": true just before authKey. The messageId starts with sozuri_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 3xx answer 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
11sentacceptedAccepted and queued for sending. On /v1/messaging this is also the answer for a scheduled message.
12unsupported_numberunsupported_numberThe number is too short to be a Kenyan mobile number. Not sent, not charged.
14—scheduledAccepted for sending at your sendAt time.
24sender_not_registeredsender_not_registeredYour 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
WhatsApp 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."
    }
}
A wrong API key or project name is refused with HTTP 401 before any channel runs; that response is the same on every channel and is documented on the Authentication page.

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.

  1. 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 a messageId you don’t recognise.
  2. Authenticate every report. Check the authKey in the body or the X-Sozuri-Signature header (see Verifying authenticity) before you act on it.
  3. 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).
  4. 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.
  5. 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.
  6. 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.
  7. 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"}
FieldTypeDescription
projectStringYour project name.
messageIdStringThe messageId the send API returned for this recipient (40 hex characters).
channelStringAlways sms.
statusStringThe outcome; see the tables below.
networkStringsafaricom or airtel.
typeStringAlways bulkDelivery.
timestampIntegerUnix seconds when we sent this webhook.
authKeyStringYour Auth Key.
Safaricom status values

Safaricom’s numeric delivery code is mapped to one of five strings before it reaches your webhook.

statusCarrier codes (input)Meaning
success0Delivered to the recipient’s phone.
network_failure1001A network error on the carrier side.
delivery_impossible1, 5, 11, 13, 21, 31, 32, 34, 99Cannot be delivered: barred number, incompatible handset, blocked content and similar.
absent_subscriber6, 27The phone was unreachable (off, or out of coverage).
unknown_erroranything elseThe 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.

statusMeaning
successDelivered to the recipient’s phone.
failedAirtel 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"}
FieldTypeDescription
projectStringYour project name.
numberStringThe customer who sent the message.
shortcodeStringYour shortcode they sent it to.
messageStringThe text they sent.
messageIdStringSozuri’s id for this inbound message (40 hex characters).
channelStringAlways interactive.
statusStringAlways success.
networkStringsafaricom or airtel.
typeStringAlways interactive.
timestampIntegerUnix seconds when we sent this webhook.
authKeyStringYour 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:

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:

typeWhen it firesstatus
activationA subscriber’s subscription became active.active
deactivationA subscriber unsubscribed.inactive
consentThe subscriber answered the network’s consent prompt.active if they accepted, inactive if they declined
linkNotificationAn on-demand request arrived. Carries the linkId you must quote in your reply.The text the subscriber sent
premiumDeliveryThe 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 statusSMS — SafaricomSMS — AirtelWhatsApp receipt
Deliveredsuccesssuccessdelivered, read
Undeliverednetwork_failure, delivery_impossible, absent_subscriber, unknown_errorfailed—
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.