Sifr Wahid Developers

Guides

Sync orders into an ERP

Webhooks tell you at once, the order is read in full, status goes back to the store, and an hourly poll closes any gap.

The design view, with a sequence diagram: Order sync.

Scopes for this sync

Orders and webhooks: read and write. Customers: read only when you need the customer's mobile, email and address on orders, or create orders for a customer by mobile. Shipments: read and write when you ship from your system.

  1. Events

    Subscribe to order.created and order.status.updated (Webhooks). On each delivery: verify the signature, drop duplicates by X-Zo-Delivery, answer 2xx at once, then do the work in the background.

  2. Details

    GET /orders/{id} with the id in the event (data.id): lines, amounts in halalas, status and payment method. The customer's contact data and address appear only with customers.read.

  3. Polling fallback

    Every hour, GET /orders?updated_since={the largest updated_at you kept}&per_page=100 and follow next_cursor. The filter is inclusive, so the last second is read again: store by id (upsert). This catches any event you missed.

  4. Status from your system to the store

    • GET /order-statuses gives, for each status, the statuses an order may move to (next).
    • POST /orders/{id}/status with {"status":"ready","note":"…"}. A move that is not allowed: 422 invalid_transition.
    • Shipping with your own carrier's tracking number: POST /orders/{id}/shipments with {"tracking_number":"…","carrier_name":"…"} and an Idempotency-Key. The order moves to shipping.

    See Change order status and Create order shipment.

  5. An order from your system (phone, point of sale)

    POST /orders with an Idempotency-Key, items by sku, a customer_id of an existing customer or a customer with name and mobile (needs customers.read; an existing customer keeps their stored name and email), and payment_method cod, bank_transfer or manual. The store works out the totals and VAT and takes the stock (409 out_of_stock when short).

    The fields: Create order.

Amounts inside webhook payloads are in riyals (two decimals), as in the dashboard's webhooks, unlike the API's answers, which are in halalas. Book the amounts from GET /orders/{id}.