API overview
About 1611 words
v1 draft
This documentation set describes the draft v1 integration contract: endpoint addresses, signing details, and error codes may still change before the official integration checklist is issued. Distributors already enabled for integration testing should treat the portal's "Integration checklist" and the actual sandbox responses as authoritative; if you find a discrepancy, please open a ticket.
The distributor-side xstock API is organized as a command namespace: the command is part of the path, and the base address is always /dist/api/v1.
- Query commands (5, including the
pingconnectivity check):GET /dist/api/v1/{cmd}. They do not use the jcmd envelope; the fields underdataare passed directly as query parameters. - Write commands (5, including the read-only
get_availandget_quote):POST /dist/api/v1/{cmd}. The request body uses the jcmd envelope.
查询 GET https://api.xstock.example/dist/api/v1/get_avail?sku_ids=sku_a,sku_b
写入 POST https://api.xstock.example/dist/api/v1/post_order
Content-Type: application/json; charset=utf-8
X-Xstock-Api-Key: <店铺 API Key>
X-Xstock-Timestamp: <Unix 秒>
X-Xstock-Signature: <签名>Integration endpoint
The domain in the examples above is a placeholder. Your actual integration address, API Key, and Secret are issued when your account is opened and your shop is created; use the values shown on the portal's "Shop details" page. The path prefix /dist/api/v1 never changes.
Integrating with Dujiao Next
If your downstream is Dujiao Next (dujiao-next), see Integrating with Dujiao Next for the endpoint and field mappings; the adapter layer handles the protocol translation.
Endpoint overview
| Endpoint | Method | Path | Permission | Idempotency |
|---|---|---|---|---|
| Connectivity ping | GET | /dist/api/v1/ping | Authentication only | Read-only |
| Get category catalog | GET | /dist/api/v1/get_categories | catalog.read | Read-only |
| Get goods list | GET | /dist/api/v1/get_goods | catalog.read | Read-only |
| Query available quantity | POST | /dist/api/v1/get_avail | avail.read | Read-only |
| Get quote | POST | /dist/api/v1/get_quote | quote.read | Read-only |
| Submit order | POST | /dist/api/v1/post_order | order.create | Keyed by req_id |
| Query orders | GET | /dist/api/v1/get_orders | order.read | Read-only |
| Cancel order | POST | /dist/api/v1/req_cancel | cancel.write | Keyed by order number |
| Open after-sales ticket | POST | /dist/api/v1/open_ticket | after_sales.write | Keyed by message ID id |
| Query after-sales ticket | GET | /dist/api/v1/req_ticket | after_sales.read | Read-only |
Specification file
The specification and the interactive structure on each page are generated from the same schema data, so the command list and field structures never drift apart. The command is the path: OpenAPI has one path per command, with get for query commands and post for write commands.
About trying calls online
Interactive "try it out" requires a sandbox environment and real signatures, and is not available yet. During integration testing, use the test shop credentials issued in the portal and implement Authentication and signing on your side.
Query commands (GET)
Query commands do not use an envelope: each field under data is passed as a query parameter, with the field name unchanged.
GET /dist/api/v1/get_goods?page=1&page_size=20- Arrays: join array parameters with a half-width comma
,, for exampleids=1,2,3. - Booleans:
true/false. - Numbers and amounts: send strings in the type given by the endpoint documentation, without thousands separators.
- No parameters: commands with no fields in
data(such asping) are called on the bare path, without?. - Field names and their casing must match the endpoint page; unrecognized fields are ignored, and a missing required field returns
1001.
The query signature is computed over the query string assembled in ascending field-name order; see Authentication and signing for the rules.
Write commands (POST)
Write command paths also carry the command name, and the request body is the jcmd envelope:
{
"id": "shop-a-20261124-0001",
"cmd": "post_order",
"data": {
"req_id": "shop-a-20261124-0001",
"items": [{ "sku_id": 1001, "qty": "1" }]
},
"stamp": 1795000000
}| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Message identifier, 1–64 characters, used for troubleshooting and reconciliation; reuse the same value when retrying |
cmd | string | Yes | Command name; must match the command in the path |
data | object | Yes | Command parameters; pass {} when there are none |
stamp | long | Yes | Unix timestamp (seconds, UTC); must match the X-Xstock-Timestamp request header |
Response envelope (jcmd)
On success, code is 0:
{
"id": "shop-a-20261124-0001",
"cmd": "get_quote",
"code": 0,
"msg": "",
"data": { },
"stamp": 1795000001
}On failure, code is non-0, data is null, and msg explains the reason:
{
"id": "shop-a-20261124-0001",
"cmd": "get_quote",
"code": 40201,
"msg": "账户可用余额不足",
"data": null,
"stamp": 1795000001
}| Field | Description |
|---|---|
id | Matches the request id |
cmd | Matches the request cmd |
code | Integer result code: 0 for success, non-0 for failure. See Errors and retries for the categories and retry strategy |
msg | Human-readable message safe to display; never branch your code on this text |
data | Business data; null on failure |
stamp | Platform processing timestamp (Unix seconds) |
Error code values
The example error codes in this documentation (such as 40201) only illustrate the format. The actual error codes and their meanings are defined by the integration checklist issued when your account is opened.
Common data types
Multilingual text
Fields shown to end users, such as names, titles, and summaries, are always a map from language tag to text, not a single string:
{ "zh-CN": "流媒体", "en": "Streaming" }- Keys are BCP-47 language tags (such as
zh-CN,en,ja), and values match the current published version. - Responses carry
default_localeat two levels: the response-level value is the site-wide fallback language; an item also has its own value for that good's fallback language (different goods may be available in different languages). - Only published languages are included; untranslated languages are omitted, and the client falls back to
default_localeor its own preferred language. - These fields are read-only. To change localized content, use the portal; the API offers no write endpoint for it.
Amounts and multi-currency prices
A single amount:
{ "amt": "10.00", "ccy": "CNY" }Prices in goods and quotes are multi-currency arrays that list every sellable currency at once:
"prices": [
{ "amt": "1.00", "ccy": "USD" },
{ "amt": "6.66", "ccy": "CNY" },
{ "amt": "1.10", "ccy": "USDT" }
]amtis a decimal string; do not parse it as a floating-point number.default_ccyexists at three levels: response, goods item, and SKU item.pricesalways contains the default currency for that level; use it for display first, then look up byccywhen the user switches currency.- Array order is not guaranteed; look up by
ccyrather than by index. - There is no automatic conversion between currencies; the platform prices each currency independently.
Quantities
{ "value": "2", "per": 1 }valueis a decimal string; integer goods increment by 1.peris the purchase step (a number), usually 1; it matchesperon the goods / SKU.
Time
All timestamps are UTC in RFC 3339 format, for example 2026-11-24T13:05:21Z. Compare them as times; do not rely on local-timezone strings.
Identifiers
Public identifiers come in two kinds, numeric IDs and GUID strings, both referring to the same object:
| Object | Numeric ID | Readable code | Description |
|---|---|---|---|
| Category | category_id | guid | The root category has parent_id 0 |
| Goods | goods_id | guid | Returned by the goods list |
| SKU | sku_id | sku_code | For single-SKU goods, sku_code is DEFAULT |
| Order | order_id | order_no | Query, cancel, and after-sales accept either order_id or order_no |
| Quote | — | quote_id | Used at order time to apply a consistent unit price |
| After-sales | — | ticket_no | Ticket number |
- Numeric IDs are protocol aliases that stay stable for downstream: once issued, they are never rebound or reused. They range from
1to9007199254740991(the JavaScript safe-integer limit); parse them as integers rather than concatenating them as strings. - The platform also has internal GUID primary keys, which are not exposed. Downstream only needs the numeric ID or the readable code to complete the mapping.
order_no,quote_id, andticket_noare business reference numbers. Treat them as opaque strings and do not parse any meaning out of them.
Pagination
List operations use page (starting at 1) and page_size (1–100, default 20):
{ "page": 1, "page_size": 50 }Responses include page, page_size, total, and has_more. Data can change between pages, so do not infer that a good has been deleted from paging results; determine delisting from the status returned by the catalog.
Permissions
Permissions are granted per shop. Calling a command you are not authorized for returns a non-0 code (msg reports the missing permission).
| Permission | Actions covered |
|---|---|
catalog.read | get_categories |
avail.read | get_avail |
quote.read | get_quote |
order.create | post_order |
order.read | get_orders |
cancel.write | req_cancel |
after_sales.write | open_ticket |
after_sales.read | req_ticket |
Rate limiting
- The default limit is 60 requests per minute per shop. Exceeding it returns HTTP 429 with a non-
0codein the response body. - The
X-RateLimit-Limit,X-RateLimit-Remaining, andRetry-Afterresponse headers help you back off. - Rate limiting does not affect idempotency semantics: a rejected request produces no business result.
Versioning
- The current protocol version is
1.0, declared via theX-Xstock-Schemarequest header; if omitted, the latest compatible version is assumed. - Newly added optional fields are backward compatible; you may ignore unknown fields.
- Changes to the meaning of amounts or quantities, or to status enums, bump the major version and are announced in the portal in advance.
- If the declared version is incompatible with the platform, a non-
0codeis returned; the request is never silently handled as an older version.
Troubleshooting tips
- Keep the
id, HTTP status code, response body, and time of every request. - On failure, check
codefirst, thenmsg. - For order-related disputes, provide the
order_noortrace_id; that locates the order faster than screenshots.