Sifr Wahid Developers

Concepts

Idempotency

Send one key per operation, and a retry after a dropped connection never runs the write twice.

The Idempotency-Key header

  • The Idempotency-Key header: 1 to 120 visible characters.
  • Required on POST /orders, POST /inventory/adjustments and POST /orders/{id}/shipments (422 without it), optional on the other writes.
  • Ignored on POST /webhooks and PATCH /webhooks/{id}, because the stored answer would keep the secret.
HTTP
POST /api/public/v1/inventory/adjustments HTTP/1.1
Host: s.zo.sa
Authorization: Bearer zo_live_...
Content-Type: application/json
Idempotency-Key: odoo-move-48213

{"items":[{"sku":"TSHIRT-BLUE-M","mode":"increment","quantity":5}]}

Choosing a key

Derive it from your document number, such as odoo-move-48213 or erp-order-SO1042: a retry after a dropped connection sends the same key, so the order or the stock movement never happens twice. Use a new key for each new operation: every write in the API reference shows one in its samples, such as erp-coupon-WELCOME10 for a new coupon.

What a key is tied to

  • Per API key: keys are kept for each API key apart, so two systems with their own keys never collide.
  • To one request: the key remembers the method, the path and the body it first came with. The same key with a different method, path or body is 422 idempotency_key_reused.

How long a key lasts

A key is kept at least 24 hours. A daily cleanup at 03:30 Riyadh time removes keys older than 24 hours, so a key may still answer for up to 48 hours. After that the same key runs as a new call.

Replays and conflicts

SituationAnswer
A second call with the same key while it is keptThe first answer back, with Idempotent-Replayed: true. Compare the two after parsing the JSON, not as text: the order of keys may differ.
The same key with a different body422 idempotency_key_reused
The same key while the first call still runs409 duplicate_request: retry in a moment
The first call ended in a 4xxReplayed as it was for the same key, so send a new key after fixing the input
The first call ended in a 5xx, or 429 images_queue_fullNot kept, so a retry with the same key runs
The first call died unfinished (a timeout, a stopped worker)It keeps its key for 300 seconds, then the next call with that key takes it over

Which writes take the key

From the OpenAPI file: every write that lists the Idempotency-Key header, and where it is required.