Qeasy Cloud
Get Started

Authoritative Tutorial on the Jushuitan Inventory Query API Field Manual (MySQL Integration)

· 卢剑航· Engineering Best Practices· 23 views· 4 min read

What This API Solves

The Jushuitan /open/inventory/query API pulls product inventory from Jushuitan into a local MySQL table jst_inventory_query. It supports multi-warehouse aggregation, inventory threshold alerts, sellable-stock calculation, and integration with ERP/BI systems. In our supply-chain integration projects, almost every customer needs this link.

API Capability Overview

  • Authentication: Standard Jushuitan Open Platform mechanism using partnerId + signature; AppKey, timestamp, and signature are passed in request headers.
  • Request Structure: POST with form/query parameters; the core parameters are wms_co_id, modified_begin, modified_end, page_index, page_size, and sku_ids.
  • Response Structure: JSON containing a datas array; each entry represents one inventory record, and the top-level has_next flag indicates whether more pages exist.
  • Pagination: page_index starts from 1; page_size defaults to 30 with a maximum of 50. Loop until has_next=false.
  • Incremental Mode: Incremental pulls are based on the modified field; the window between modified_begin and modified_end must not exceed 7 days, otherwise the API returns an error.
  • Special Queries: When wms_co_id is omitted or set to 0, the response returns total stock across all warehouses. sku_ids accepts up to 20 SKUs and cannot be empty together with the modification-time window.

Typical Field Mapping

FieldTypeMeaningPractical Notes
i_idstringInventory record primary keyRecommend a composite key {{sku_id}}-{{wms_co_id}}-{{ts}} in MySQL to avoid cross-warehouse conflicts
sku_idstringSKU codenumber in metadata points to this field; used as business key
namestringProduct namePaired with sku_id for human identification
qtystringAvailable stockReal sellable quantity, often combined with virtual/lock fields
virtual_qtystringVirtual stockVirtual additions such as presales and reservations
purchase_qtystringIn-transit purchasesPurchase orders not yet received
allocate_qtystringAllocated quantityAllocated but not yet shipped
order_lockstringOrder lockReserved by orders; reduces sellable
pick_lockstringPick lockLocked during picking
in_qtystringInbound in-transitInbound not yet completed
return_qtystringReturn in-transitReturns not yet received
defective_qtystringDefectiveNon-sellable stock
min_qty / max_qtystringThreshold valuesUsed for low/over-stock alerts
modifiedstringModified timeKey field for incremental pull; rely on the server time
tsstringTimestampSync timestamp, often used as an idempotency helper key

A common empirical formula for sellable stock: qty + virtual_qty - order_lock - pick_lock - allocate_qty. Confirm the exact formula with the Jushuitan business rule.

How to Configure on Qeasy

In the Qeasy Data Integration Platform, this API is usually wrapped as the "Jushuitan-Inventory Query" adapter under the Jushuitan Open Platform connector. The recommended configuration steps are:

  1. Connector: Select the Jushuitan adapter and enter partnerId, AppKey, and AppSecret; the platform generates the signature automatically.
  2. Request Template: Bind modified_begin / modified_end to the platform variables {{LAST_SYNC_TIME}} and {{CURRENT_TIME}} to implement the incremental window.
  3. Field Mapper: The Qeasy field mapper automatically flattens datas[*] into rows, using the expression {{sku_id}}-{{wms_co_id}}-{{ts}} as the primary key.
  4. Target: Write into the MySQL table jst_inventory_query; Qeasy generates REPLACE INTO batch writes by default to prevent duplicates.
  5. Post-Script: Mount a script in the AfterTargetGenerate phase to convert empty strings to null and to filter emoji and four-byte characters, avoiding MySQL write errors.
  6. Scheduling: A crontab of 20 */2 * * * (every 2 hours) is recommended; it stays well below the 7-day window and covers most alerting needs.

Cross-Project Practical Points

  1. Never exceed the 7-day window: Many customers have hit this hard limit. Keep a 1–2 hour overlap to avoid missing records.
  2. Use wms_co_id to distinguish warehouses: Both aggregate and per-warehouse queries use the same API but require different parameters; keep the column in MySQL.
  3. Do not be greedy with page_size: We have observed timeouts when page_size=50 and data volume is large; 30 is the safe choice.
  4. Use a composite primary key: i_id alone can collide; sku_id+wms_co_id+ts is the most stable option.
  5. All quantity fields are strings: Store them as VARCHAR or explicitly CAST to DECIMAL; do not treat them as numbers.
  6. Clean empty strings: Jushuitan frequently returns ""; convert them to null before storing to keep MySQL indexes healthy.

Pitfall Recap

  • Truncated 7-day window: A first-time run with a 30-day window failed immediately. The safe approach is a 2-hour rolling window with a 1-hour overlap on modified.
  • 504 timeouts from large page_size: A retail customer with very large single-warehouse data hit frequent timeouts at page_size=50; reducing to 30 stabilized the integration.
  • MySQL errors from emoji characters: Product names containing emoji broke utf8 writes; filter four-byte characters in AfterTargetGenerate.
  • Mixing aggregate and per-warehouse data: Some projects wrote aggregate and per-warehouse data into the same row, doubling the inventory; always split by wms_co_id.
  • Treating quantities as INT: All quantity fields are strings. Writing "" into an INT column silently becomes 0, skewing sellable stock. Convert to NULL or DECIMAL before writing.

When to Use

Choose this API when you need to localize Jushuitan inventory, perform multi-warehouse aggregation, drive inventory alerts, or feed BI/ERP. If you only need real-time sellable quantity for a single SKU and have no batch-analysis requirement, calling Jushuitan's front-end API directly is lighter. This API is not designed for second-level real-time inventory; the 2-hour cadence is the most cost-effective rhythm.

Original content. Please credit the source when reposting: https://www.qeasy.cloud/insights/engineering/hb-p2-012-mysql-ok-19fd

Comments