Webhooks
Outbound webhooks
Wijha sends a signed JSON event to your HTTPS URL when something happens to an order or your catalogue. Every delivery is signed with your endpoint's secret, carries a stable event id, and is retried until your server answers 2xx.
Manage endpoints
Open Merchant Portal → Developers → Webhooks. Each endpoint has:
- Nickname — optional label shown in the portal.
- URL — HTTPS destination for deliveries.
- Method — POST (default), PUT, PATCH, or GET.
- Events — one or more event names from the catalogue below (or * for all).
- Signing secret — generated by Wijha when you create the endpoint (whsec_…) and shown once. Copy it into your server's config; afterwards the portal only shows a hint (whsec_…abcd).
You can also manage endpoints via the API (POST /api/v1/webhooks/endpoints, scope webhooks.write); the create response carries secret once.
Verify the signature
Every delivery carries Wijha-Signature: t=<unix seconds>,v1=<hex>. v1 is HMAC-SHA256 of the string `${t}.${rawBody}` keyed with your secret, in lowercase hex. To verify:
- Read the raw request body as bytes — before any JSON parsing or re-encoding.
- Split the header on commas: t is the timestamp, each v1 is one signature (there are two during a secret rotation).
- Reject the request when |now − t| is more than 5 minutes (replay protection).
- Compute HMAC-SHA256(secret, `${t}.${rawBody}`) and compare it with each v1 using a constant-time comparison. Accept if any matches.
- Deduplicate on Wijha-Event-Id: retries and redeliveries reuse it.
const crypto = require("crypto");
const express = require("express");
const TOLERANCE_SEC = 300; // reject anything older / newer than 5 minutes
/** secrets: every secret you trust right now (new + old during a 24 h rotation). */
function verifyWijhaSignature({ header, rawBody, secrets }) {
if (!header) return false;
let t = null;
const sigs = [];
for (const part of header.split(",")) {
const [k, v] = part.split("=");
if (k === "t") t = Number(v);
if (k === "v1") sigs.push(v);
}
if (!t || !sigs.length) return false;
if (Math.abs(Math.floor(Date.now() / 1000) - t) > TOLERANCE_SEC) return false;
return secrets.some((secret) => {
const expected = crypto
.createHmac("sha256", secret)
.update(`${t}.${rawBody}`)
.digest("hex");
return sigs.some(
(sig) =>
sig.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(sig, "hex"), Buffer.from(expected, "hex")),
);
});
}
const seen = new Set(); // use your database in production
const app = express();
// Keep the raw body: the signature covers the exact bytes we sent.
app.post("/hooks/wijha", express.raw({ type: "application/json" }), (req, res) => {
const rawBody = req.body.toString("utf8");
const ok = verifyWijhaSignature({
header: req.get("Wijha-Signature"),
rawBody,
secrets: [process.env.WIJHA_WEBHOOK_SECRET, process.env.WIJHA_WEBHOOK_SECRET_OLD].filter(Boolean),
});
if (!ok) return res.status(401).send("invalid signature");
const eventId = req.get("Wijha-Event-Id");
if (seen.has(eventId)) return res.status(200).send("duplicate"); // retries / redeliveries
seen.add(eventId);
const event = JSON.parse(rawBody);
if (event.event === "order.delivery_failed") {
// event.changes.reasonCode, event.changes.attempts, event.changes.waybillRef …
}
res.status(200).send("ok"); // answer fast; do heavy work async
});<?php
const TOLERANCE_SEC = 300;
function wijha_verify(string $header, string $rawBody, array $secrets): bool {
$t = null;
$sigs = [];
foreach (explode(',', $header) as $part) {
[$k, $v] = array_pad(explode('=', $part, 2), 2, '');
if ($k === 't') $t = (int) $v;
if ($k === 'v1') $sigs[] = $v;
}
if (!$t || !$sigs) return false;
if (abs(time() - $t) > TOLERANCE_SEC) return false; // replay protection
foreach ($secrets as $secret) {
if (!$secret) continue;
$expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
foreach ($sigs as $sig) {
if (hash_equals($expected, $sig)) return true;
}
}
return false;
}
$rawBody = file_get_contents('php://input'); // raw bytes, before json_decode
$header = $_SERVER['HTTP_WIJHA_SIGNATURE'] ?? '';
$secrets = [getenv('WIJHA_WEBHOOK_SECRET'), getenv('WIJHA_WEBHOOK_SECRET_OLD')];
if (!wijha_verify($header, $rawBody, $secrets)) {
http_response_code(401);
exit('invalid signature');
}
$eventId = $_SERVER['HTTP_WIJHA_EVENT_ID'] ?? '';
// Skip $eventId if you have already processed it (retries reuse the same id).
$event = json_decode($rawBody, true);
http_response_code(200);
echo 'ok';Rotate the secret
Use Rotate secret in the portal (or POST /api/v1/webhooks/endpoints/:id/rotate-secret). The new secret is shown once. For the next 24 hours every delivery is signed with both secrets — the header carries two v1 values — so:
- Deploy the new secret next to the old one (verify against both).
- Remove the old secret once you are on the new one; after 24 hours only the new secret signs.
- previousSecretExpiresAt on the endpoint tells you when the overlap ends.
POST /api/v1/webhooks/endpoints/wh_01J/rotate-secret
Authorization: Bearer wjh_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx{
"status": 200,
"message": "ok",
"data": {
"id": "wh_01J",
"secret": "whsec_N8pd…(new — shown once)…3fAa",
"secretHint": "whsec_…3fAa",
"secretRotatedAt": "2026-11-25T09:00:00.000Z",
"previousSecretExpiresAt": "2026-11-26T09:00:00.000Z"
}
}Request headers
Every delivery includes:
- Content-Type: application/json
- User-Agent: Wijha-Webhooks/1.1
- Wijha-Signature — t=<unix seconds>,v1=<hex>[,v1=<hex>]
- Wijha-Event-Id — the event id (same as id in the body); stable across retries and redeliveries
- Wijha-Event-Type — the event name, e.g. order.delivered
- Wijha-Delivery-Id — this delivery row (changes on a redelivery)
- X-Wijha-Timestamp / X-Wijha-Signature — legacy pair (milliseconds timestamp, HMAC of `${ms}.${rawBody}` with the current secret). Kept for existing receivers; new integrations should use Wijha-Signature.
POST /hooks/wijha HTTP/1.1
Host: example.com
Content-Type: application/json
User-Agent: Wijha-Webhooks/1.1
Wijha-Event-Id: evt_5b7e1c9d2a4f6e8b0c3d5a7e9f
Wijha-Event-Type: order.status_changed
Wijha-Delivery-Id: del_01JSTAT
Wijha-Signature: t=1791555611,v1=5f2b8c…e41a
{"id":"evt_5b7e1c9d2a4f6e8b0c3d5a7e9f","deliveryId":"del_01JSTAT","event":"order.status_changed",…}Delivery, retries and the delivery log
When a subscribed event fires, Wijha queues a delivery and sends it promptly:
- Up to 6 attempts in total (1 initial + 5 retries). Retry delays: 30s → 2m → 10m → 1h → 6h.
- Answer 2xx within 15 seconds; any other status, a redirect or a timeout counts as a failure.
- Delivery log — Developers → Webhooks → Deliveries (or GET /api/v1/webhooks/deliveries) shows each delivery's status, attempts, response code, duration and the exact JSON body.
- Redeliver — re-sends a delivery now with the same event id and body (POST /api/v1/webhooks/deliveries/:id/redeliver). If it fails again it follows the normal retry schedule.
- Send test event — a signed webhook.test delivery to check your endpoint and signature code; it is logged but never retried.
- Continuous failure for about one week pauses the endpoint and notifies the store; reactivate it after fixing your receiver.
GET /api/v1/webhooks/deliveries?endpointId=wh_01J&status=dead&limit=20
Authorization: Bearer wjh_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx{
"status": 200,
"message": "ok",
"data": {
"items": [
{
"id": "del_01JDEX",
"endpointId": "wh_01J",
"eventId": "evt_e1a3c5b7d9f2468a0c2e4b6d8f",
"eventType": "order.delivery_failed",
"status": "dead",
"attempts": 6,
"responseStatus": 503,
"durationMs": 412,
"lastError": "HTTP 503",
"lastAttemptAt": "2026-10-10T01:12:00.000Z",
"nextAttemptAt": null,
"deliveredAt": null,
"redeliveryOf": null,
"isTest": false,
"createdAt": "2026-10-09T13:05:42.000Z"
}
],
"nextPageToken": null
}
}POST /api/v1/webhooks/deliveries/del_01JDEX/redeliver
Authorization: Bearer wjh_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# → a new delivery row (redeliveryOf = del_01JDEX) with the same eventId, sent at onceEvent catalogue
Subscribe to any of these names. Every status change of an order is sent as order.status_changed; the outcome events are sent in addition, so you can subscribe to just the outcome you care about:
- order.created — a new order (booked with a waybill)
- order.updated — order fields changed (customer, address, items, notes …)
- order.status_changed — every operational event: changes.event = { code, labelEn, labelAr }, from, to, reasonCode, outcome, attempts, waybillRef
- order.delivered — delivered to the customer (DTR, or a partner status DELIVERED); outcome = FULL / PARTIAL / EXCHANGED
- order.delivery_failed — a failed delivery attempt (DEX or a partner EXCEPTION); reasonCode says why, attempts counts doorstep tries
- order.returned — the parcel is back with you (RTRN)
- order.cancelled — cancelled before pickup (CNL). A cancel after pickup becomes a return: you get order.status_changed (to RETURNING) and later order.returned
- order.return_leg_created — a return leg (waybill-R1 …) was created to bring items back after a partial delivery or an exchange
- product.updated · collection.updated · customer.created · customer.updated · inventory.adjusted · stock.received
- Change requests (order.change_request.*) — coming soon
Engine codes in changes.event.code: PKR created · RDY ready · PKA / PKU pickup (un)assigned · PKP picked up · RITS received at hub · HND handed over from fulfilment · BMT / BMR branch transfer · OTD out for delivery · DTR delivered · DEX delivery failed · HLD on hold · RSC rescheduled · RTS return decided · OTR out for return · RTRN returned · CNL cancelled · LST lost · DMG damaged · HTP / PSM partner · AUTO_* automatic rules · UNDO correction. Older names (OrderCreated, OrderStatusChanged, ShipmentDelivered …) are still accepted on subscriptions and saved as the new names.
Delivery JSON
Each attempt sends this envelope. id is the event id (= Wijha-Event-Id); data holds full entity snapshots; changes holds the event facts.
{
"id": "evt_3f9c2a71d0b84e5a6c1f2e9a0b",
"deliveryId": "del_01JABCXYZ",
"event": "order.created",
"eventType": "order.created",
"storeId": "str_01JSTORE",
"occurredAt": "2026-10-08T17:12:04.128Z",
"data": {
"order": {
"id": "ord_01JABC",
"storeId": "str_01JSTORE",
"number": "10042",
"channel": "portal",
"status": "NEW",
"orderType": "DLV_COD",
"waybill": "WJ473124829",
"waybillRef": "WJ473124829",
"legNo": 0,
"fulfilmentSource": "merchant",
"customerId": "cus_01JDEF",
"customerName": "Ahmed Hassan",
"customerPhone": "+201012345678",
"shippingAddress": {
"line1": "12 Nile St",
"phone": "+201012345678",
"zoneId": "zon_01JNASR7",
"governorateCode": "EG-C",
"cityCode": "C-07",
"state": "القاهرة",
"city": "مدينة نصر",
"area": "الحي السابع"
},
"lineItems": [
{
"id": "itm_01J",
"lineNo": 1,
"productId": "prd_01J",
"variantId": "var_01J",
"sku": "TEE-BLK-M",
"title": "Cotton tee",
"qty": 2,
"price": 225
}
],
"payment": { "method": "cod", "codAmount": 495, "currency": "EGP" },
"paymentStatus": "UNPAID",
"codAmountPiasters": 49500,
"attempts": 0,
"totals": {
"subtotal": 450,
"shipping": 45,
"total": 495,
"currency": "EGP"
},
"createdAt": "2026-10-08T17:12:04.000Z"
},
"customer": {
"id": "cus_01JDEF",
"name": "Ahmed Hassan",
"phone": "+201012345678",
"email": "ahmed@example.com"
}
},
"changes": {
"aggregateType": "order",
"aggregateId": "ord_01JABC"
}
}Only related keys appear in data for a given event. If a related entity cannot be loaded, that key is omitted; changes still arrive.
order.status_changed example
Sent on every status change. changes carries the engine event (code + English / Arabic label), from / to (catalogue codes), reasonCode, outcome, attempts and waybillRef:
{
"id": "evt_5b7e1c9d2a4f6e8b0c3d5a7e9f",
"deliveryId": "del_01JSTAT",
"event": "order.status_changed",
"eventType": "order.status_changed",
"storeId": "str_01JSTORE",
"occurredAt": "2026-10-09T14:20:11.000Z",
"data": {
"order": {
"id": "ord_01JABC",
"number": "10042",
"status": "DELIVERED",
"orderType": "DLV_COD",
"waybill": "WJ473124829",
"waybillRef": "WJ473124829",
"attempts": 1,
"outcome": "FULL",
"paymentStatus": "COLLECTED_CASH",
"codAmountPiasters": 49500,
"pickedUpAt": "2026-10-08T19:02:00.000Z",
"deliveredAt": "2026-10-09T14:20:10.000Z",
"statusChangedAt": "2026-10-09T14:20:10.000Z"
},
"shipment": {
"orderId": "ord_01JABC",
"carrier": "wijha",
"status": "DELIVERED",
"trackingNumber": "WJ473124829",
"waybill": "WJ473124829",
"deliveryAttempts": 1
}
},
"changes": {
"aggregateType": "order",
"aggregateId": "ord_01JABC",
"from": "OUT_FOR_DELIVERY",
"to": "DELIVERED",
"status": "DELIVERED",
"number": "10042",
"orderType": "DLV_COD",
"waybill": "WJ473124829",
"eventCode": "DTR",
"event": { "code": "DTR", "labelEn": "Delivered", "labelAr": "تم التسليم" },
"reasonCode": null,
"outcome": "FULL",
"attempts": 1,
"waybillRef": "WJ473124829"
}
}order.delivery_failed example
{
"id": "evt_e1a3c5b7d9f2468a0c2e4b6d8f",
"deliveryId": "del_01JDEX",
"event": "order.delivery_failed",
"eventType": "order.delivery_failed",
"storeId": "str_01JSTORE",
"occurredAt": "2026-10-09T13:05:42.000Z",
"data": {
"order": { "id": "ord_01JABC", "number": "10042", "status": "EXCEPTION", "attempts": 1 }
},
"changes": {
"aggregateType": "order",
"aggregateId": "ord_01JABC",
"number": "10042",
"event": { "code": "DEX", "labelEn": "Delivery failed", "labelAr": "تعذر التسليم" },
"eventCode": "DEX",
"from": "OUT_FOR_DELIVERY",
"to": "EXCEPTION",
"reasonCode": "NO_ANSWER",
"outcome": null,
"attempts": 1,
"waybillRef": "WJ473124829"
}
}product.updated example
{
"id": "evt_8a1d6e0c4b2f9a3e7d5c1b0a9f",
"deliveryId": "del_01JPROD",
"event": "product.updated",
"eventType": "product.updated",
"storeId": "str_01JSTORE",
"occurredAt": "2026-10-08T16:40:00.000Z",
"data": {
"product": {
"id": "prd_01J",
"title": "Cotton tee",
"status": "active",
"price": 225,
"currency": "EGP",
"sku": "TEE-BLK-M"
}
},
"changes": {
"aggregateType": "product",
"aggregateId": "prd_01J",
"action": "updated"
}
}customer.created example
{
"id": "evt_c4e2b9a17f0d3e6a5b8c2d1e0f",
"deliveryId": "del_01JCUS",
"event": "customer.created",
"eventType": "customer.created",
"storeId": "str_01JSTORE",
"occurredAt": "2026-10-08T15:05:22.000Z",
"data": {
"customer": {
"id": "cus_01JDEF",
"name": "Ahmed Hassan",
"phone": "+201012345678",
"email": "ahmed@example.com",
"createdAt": "2026-10-08T15:05:22.000Z"
}
},
"changes": {
"aggregateType": "customer",
"aggregateId": "cus_01JDEF"
}
}Migrating from the old events
Endpoints created before signed webhooks were moved over automatically:
- Subscriptions were renamed: OrderCreated → order.created, OrderUpdated → order.updated, OrderStatusChanged → order.status_changed, ProductUpdated → product.updated, CustomerCreated / CustomerUpdated → customer.*, InventoryAdjusted → inventory.adjusted, StockReceived → stock.received.
- The retired shipment events map to order events: ShipmentCreated → order.created, ShipmentDelivered → order.delivered, ShipmentCreateFailed → order.delivery_failed.
- Endpoints that had a secret keep it (now stored encrypted). Endpoints without one got a generated secret — rotate it in the portal to see it, then verify Wijha-Signature.
- The envelope id is now the event id (stable across retries); the delivery row id moved to deliveryId.
Expected responses
Your endpoint should acknowledge quickly:
- 2xx — delivery marked successful; consecutive failure window cleared.
- Other status or timeout — counted as failure; retries follow the schedule above.
- GET deliveries send the same headers; body is omitted for GET (the signature still covers the body we would have sent).
HTTP/1.1 200 OK
Content-Type: text/plain
ok