Your First Order
About 635 words
Let us walk the entire chain with a minimal example. Assume you already have an API Key and Secret, the product SKU is 1001, and the quantity is 1.
Call sequence
get_goods → find the product and SKU
get_avail → confirm availability
get_quote → obtain a quote (optional but recommended)
post_order → place the order, balance held
↓ async
order.fulfilled callback (or poll get_orders)
↓
get_orders → fetch deliverables with delivers1. Pull the product list
GET /dist/api/v1/get_goods?page=1&page_size=20 HTTP/1.1
Host: api.xstock.example
X-Xstock-Api-Key: xs_live_xxxxxxxx
X-Xstock-Timestamp: 1795000000
X-Xstock-Signature: 9f2c...The returned data.items is the product list, and each product carries a skus array; a SKU includes fields such as sku_id, sku_code, prices, and stock_status. If you have not set up category mappings yet, call get_categories first to pull the category catalog.
2. Confirm availability
get_avail is a POST using the jcmd envelope, queried by product (guid takes precedence over goods_id):
{
"id": "demo-avail-1",
"cmd": "get_avail",
"data": {
"items": [
{ "goods_id": 501, "skus": [{ "sku_id": 1001 }] }
]
},
"stamp": 1795000000
}available_qty is a snapshot value, intended only for display and judgement; whether an order succeeds is determined by the acceptance result, and it does not lock stock. Omitting skus returns the availability of all SKUs under that product.
3. Obtain a quote
get_quote is likewise a POST, taking the unit price by product (without quantity):
{
"id": "demo-quote-1",
"cmd": "get_quote",
"data": {
"items": [
{ "goods_id": 501, "skus": [{ "sku_id": 1001 }] }
]
},
"stamp": 1795000000
}The response contains quote_id, the product-level prices, and the prices of each SKU. A quote is a unit price and does not include quantity; the transaction amount = unit price × order quantity. When prices change, simply obtain a new quote.
4. Place the order
Endpoint: POST /dist/api/v1/post_order, with the request body in the jcmd envelope.
{
"id": "demo-order-1",
"cmd": "post_order",
"data": {
"req_id": "shop-a-20261124-0001",
"dstm_order_ref": "202611240001",
"trace_id": "trace-demo-1",
"callback_uri": "https://shop-a.example/api/xstock/callback",
"quote_id": "q_xxxxxxxx",
"items": [{ "sku_id": 1001, "qty": 1 }]
},
"stamp": 1795000000
}req_id is the idempotency key and must be generated reliably by your system: repeated submissions of the same business case must use the same value, and new business cases must use a new value.
A successful response:
{
"id": "demo-order-1",
"cmd": "post_order",
"code": 0,
"msg": "",
"data": {
"req_id": "shop-a-20261124-0001",
"trace_id": "trace-demo-1",
"accept_state": "accepted",
"order_id": 9001,
"order_no": "XS20261124000123",
"status": "paid",
"fund_state": "held",
"total": {
"amt": "10.00",
"ccy": "CNY"
},
"created_at": "2026-11-24T13:05:21Z",
"lines": [
{
"line_no": 1,
"sku_id": 1001,
"sku_guid": "5d8f2a6c9e1b4d3f8a7c0e2b5d9f1a3c",
"qty": 1,
"unit_price": {
"amt": "10.00",
"ccy": "CNY"
}
}
]
},
"stamp": 1795000001
}At this point the balance has been held but not yet charged. Submitting the same req_id again returns the same order number and the same amount (code=0), with no duplicate charge.
5. Wait for delivery
Delivery is asynchronous: once the whole order is fully sourced, the platform delivers it in one go and charges the amount, while also sending an order.fulfilled event.
Receiving the callback (recommended):
{
"event_id": "evt_01J...",
"event_type": "order.fulfilled",
"occurred_at": "2026-11-24T13:05:48Z",
"data": {
"order_id": 9001,
"order_no": "XS20261124000123",
"fulfill_state": "full",
"fund_state": "captured",
"total": {
"amt": "10.00",
"ccy": "CNY"
}
}
}Or poll actively:
GET /dist/api/v1/get_orders?order_no=XS20261124000123 HTTP/1.1
Host: api.xstock.example
X-Xstock-Api-Key: xs_live_xxxxxxxx
X-Xstock-Timestamp: 1795000000
X-Xstock-Signature: 9f2c...How to judge failures
| Response | Meaning | What you should do |
|---|---|---|
1xxx / 2xxx | Explicit rejection, e.g. insufficient balance or product delisted | Do not retry; fix the issue and place the order again |
3002 | The content of the same req_id is inconsistent | Check the request body; if it really is new business, use a new key |
4xxx | Temporary failure | Retry with backoff (same key, same content) |
9xxx | Uncertain result | Do not retry the order; query with get_orders by trace_id to confirm |
For details on the error classes, see Errors and Retries.