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.
Events
Subscribe to
order.createdandorder.status.updated(Webhooks). On each delivery: verify the signature, drop duplicates byX-Zo-Delivery, answer 2xx at once, then do the work in the background.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 withcustomers.read.Polling fallback
Every hour,
GET /orders?updated_since={the largest updated_at you kept}&per_page=100and follownext_cursor. The filter is inclusive, so the last second is read again: store by id (upsert). This catches any event you missed.Status from your system to the store
GET /order-statusesgives, for each status, the statuses an order may move to (next).POST /orders/{id}/statuswith{"status":"ready","note":"…"}. A move that is not allowed: 422invalid_transition.- Shipping with your own carrier's tracking number:
POST /orders/{id}/shipmentswith{"tracking_number":"…","carrier_name":"…"}and anIdempotency-Key. The order moves to shipping.
See Change order status and Create order shipment.
An order from your system (phone, point of sale)
POST /orderswith anIdempotency-Key,itemsbysku, acustomer_idof an existing customer or acustomerwith name and mobile (needscustomers.read; an existing customer keeps their stored name and email), andpayment_methodcod,bank_transferormanual. The store works out the totals and VAT and takes the stock (409out_of_stockwhen 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}.