Sifr Wahid Developers

Guides

Webhooks

Subscribe a public https address to an event, verify every delivery, answer fast, and use the log, resend and test tools.

Create webhooks through the API

For an integration, create the webhook with your key, through the API:

Shell
curl -sS https://s.zo.sa/api/public/v1/webhooks -H "Authorization: Bearer $ZO_API_KEY" \
  -H "Content-Type: application/json" -H "Accept: application/json" \
  -d '{"name":"ERP orders","event":"order.created","url":"https://erp.example.com/zo/hooks","security_strategy":"signature","signature_version":2}'

Webhooks made in the dashboard (Developer tools → Webhooks) always use signature version 1, and a key cannot see them: GET, test, deliveries, resend and a new secret on a dashboard webhook answer 404 to the key. Make your integration's webhooks with the key, and the go-live checklist's "signature v2" means a webhook made this way.

  • The URL is https on a public address. One event per webhook; every event is in GET /webhooks/events and on Webhook events. A store has 10 webhooks (Pro), shared by the dashboard and every key, and a key sees only the ones it made.
  • Subscribing to an event needs the read scope of the event's resource, else 403 insufficient_scope: order.* needs orders.read, product.* needs products.read, customer.* needs customers.read, and so on (GET /webhooks/events names the scope of each event). Scopes are checked again at every send.
  • The secret is shown once, in the create answer (secret). Keep it. To change it, POST /webhooks/{id}/secret; the old one stops at once.
  • Webhook create and update ignore an Idempotency-Key: a retry after a lost answer makes a second webhook, so list GET /webhooks and delete the extra one.

Every field of a webhook: Create webhook.

Security strategies

security_strategyWhat the receiver gets
signature (the default)X-Zo-Signature, the hex HMAC-SHA256 with the webhook's secret. signature_version 1 (the default) signs the raw body; 2 (recommended) signs "{timestamp}.{body}" and also sends X-Zo-Timestamp.
tokenAuthorization: Bearer <secret>, and no signature: compare the token with the secret you kept.
noneNeither: nothing proves the delivery came from Sifr Wahid.

Deliveries

Every delivery is a JSON POST (Content-Type: application/json) with the body {event, merchant, created_at, data}, where merchant is the store id:

JSON
{
  "event": "order.created",
  "merchant": 123,
  "created_at": "2026-11-08T13:41:48+03:00",
  "data": {
    "id": 1,
    "reference_id": 1001,
    "status": "under_review",
    "total": 150,
    "...": "..."
  }
}
HeaderWhenWhat it holds
X-Zo-EventAlwaysThe event, such as order.created
X-Zo-DeliveryAlwaysThe delivery id; the same id on a retry, so use it to drop duplicates. A resend is a new delivery with a new id.
X-Zo-Security-StrategyAlwaysSignature, Token or None
User-AgentAlwaysZoSa-Webhooks/1.0
X-Zo-SignatureStrategy signatureThe hex HMAC-SHA256 signature (version 1 or 2)
X-Zo-TimestampSignature version 2 onlyUnix seconds, part of what is signed
AuthorizationStrategy tokenBearer <secret>

The webhook's own custom headers come too (below).

Note: amounts inside webhook payloads are in riyals (two decimals), as in the dashboard's webhooks, unlike the API's answers, which are in halalas. The envelope's created_at is in the Riyadh offset (+03:00), while dates in the API's answers are UTC. Names in a payload are a single text: the Arabic name, or the English one when there is none.

Verifying the signature (version 2)

X-Zo-Signature is the hex HMAC-SHA256 of "{timestamp}.{body}" with the secret, where body is the request body exactly as it arrived, before any parsing. Refuse a timestamp more than 300 seconds away:

PHP
function zo_verify(string $body, string $secret, string $signature, ?string $timestamp, int $tolerance = 300): bool
{
    if ($timestamp === null) { // version 1
        return hash_equals(hash_hmac('sha256', $body, $secret), strtolower($signature));
    }
    if (! preg_match('/^\d{1,12}$/', $timestamp) || abs(time() - (int) $timestamp) > $tolerance) {
        return false;
    }

    return hash_equals(hash_hmac('sha256', $timestamp.'.'.$body, $secret), strtolower($signature));
}

// $ok = zo_verify(file_get_contents('php://input'), $secret, $_SERVER['HTTP_X_ZO_SIGNATURE'] ?? '', $_SERVER['HTTP_X_ZO_TIMESTAMP'] ?? null);
Node
const crypto = require('crypto');

// rawBody: the request body as a Buffer or string, before any JSON parsing
function zoVerify(rawBody, secret, signature, timestamp, tolerance = 300) {
  let signed = rawBody;
  if (timestamp != null) { // version 2
    if (!/^\d{1,12}$/.test(timestamp) || Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)) > tolerance) return false;
    signed = Buffer.concat([Buffer.from(timestamp + '.'), Buffer.from(rawBody)]);
  }
  const expected = Buffer.from(crypto.createHmac('sha256', secret).update(signed).digest('hex'));
  const given = Buffer.from(String(signature || '').toLowerCase());
  return given.length === expected.length && crypto.timingSafeEqual(given, expected);
}

// const ok = zoVerify(req.rawBody, secret, req.get('X-Zo-Signature'), req.get('X-Zo-Timestamp') ?? null);
Python
import hashlib
import hmac
import re
import time


def zo_verify(body: bytes, secret: str, signature: str, timestamp: str | None, tolerance: int = 300) -> bool:
    if timestamp is None:  # version 1
        signed = body
    else:  # version 2
        if not re.fullmatch(r"\d{1,12}", timestamp) or abs(int(time.time()) - int(timestamp)) > tolerance:
            return False
        signed = timestamp.encode() + b"." + body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, (signature or "").lower())

# ok = zo_verify(request.get_data(), secret, request.headers.get("X-Zo-Signature", ""), request.headers.get("X-Zo-Timestamp"))

Full files on GitHub: verify.php, verify.js and verify.py.

Version 1 signs the raw body alone and sends no X-Zo-Timestamp: the functions above check it when the timestamp is null (None in Python).

Receiver requirements

  • No redirects are followed. A redirect is a failed delivery: an http address that redirects to https, or a path that redirects to add a trailing slash, never reaches your code. Register the exact final URL.
  • Ports 80 and 443 only, and a host name written in plain ASCII: use the punycode form (xn--...) of an international name.
  • A public address: never a private, loopback or link-local one.
  • Only the first 10 KB of your answer is kept in the delivery log.
  • A store sends at most 120 deliveries a minute; deliveries past that wait for the next minute without being tried.

Custom headers

headers adds up to 10 headers of your own to every delivery, such as a header your gateway checks. A name is letters, digits and dashes, up to 64 characters; a value is up to 500 characters on one line. These names are refused, because the platform sets them: Host, Content-Type, Content-Length, User-Agent, Authorization, Connection, Transfer-Encoding, Expect and every X-Zo-*. Values are masked (••••••) on every read; send the mask back in a PATCH to keep a stored value.

Rules

rule sends a delivery only when the event's payload matches, such as total > 100 AND cash_on_delivery = true.

  • Conditions are attribute operator value, joined with AND or OR. AND binds tighter, there are no brackets, and a rule holds up to 10 conditions (500 characters).
  • Operators: =, !=, >, <, >=, <=.
  • Values: numbers, true, false, null, or text in backticks or quotes. Text compares ignoring case and surrounding spaces.
  • The attributes are the payload's flat attributes for the event's kind, listed on Webhook events. Amounts are in riyals there. A rule with an unknown attribute is refused when you save it.

Retries

  • Answer any 2xx within 15 seconds. Otherwise the delivery is tried 3 more times, 5 minutes apart.
  • After 50 failures in a row, or 10 timeouts in a row, the webhook switches itself off and the owner is told. Switch it back on with PATCH /webhooks/{id} and {"is_active": true} once the receiver is fixed.

Test send and redelivery

  • POST /webhooks/{id}/test sends a sample now (the store's latest subject of the event's kind, or an empty sample) and answers its result; your receiver has 5 seconds (1 to connect). It never counts as a failure. When every outbound slot is busy it is queued, and the answer adds queued: true. 10 test sends a minute.
  • GET /webhooks/{id}/deliveries is the last 30 days, and POST /webhooks/{id}/deliveries/{delivery}/resend sends the same event again as a new delivery: it answers 202 with status pending; read the outcome later with GET /webhooks/{id}/deliveries/{delivery}. 20 resends a minute.

The whole lifecycle, with a diagram: Webhook delivery lifecycle.