Export back-in-stock demand for inventory planning
Worked recipe: pull every variant shoppers are waiting for, with stock, price and how long they've waited, into a CSV a buying team can sort. Every call, response and error code.
Last updated
For: agencies, operations and buying teams who decide what to restock first.
Goal: a CSV of every variant with shoppers waiting on it (pending signups, all-time signups, live stock, price and the last request), sorted by demand, plus how long shoppers wait for the top items.
Before you start
Section titled “Before you start”- Credentials: the store’s API key (
X-Auth-Token) or an MCP client signed in to the store. This recipe only reads. - Plan: the demand table works on every plan. The wait-time histogram (
distribution) is paid only: the free plan gets the median and longest wait. - Tools:
curlandjqfor the CSV, or any HTTP client. - There is no CSV export endpoint in the API: you page through the JSON and write the CSV yourself, as below.
1. Read the totals first
Section titled “1. Read the totals first”curl "https://app.stoqapp.com/api/v2/external/back_in_stock/reports/products_in_demand?range=all_time&per_page=1&include_totals=true" \ -H "X-Auth-Token: $STOQ_API_KEY"{ "tool": "execute_read", "arguments": { "method": "GET", "path": "/back_in_stock/reports/products_in_demand", "params": { "range": "all_time", "per_page": 1, "include_totals": true } } }{ "window": null, "group_by": "variant", "sort_by": "pending", "direction": "desc", "count_by": "customers", "rows": [ { "…": "…" } ], "totals": { "pending": 1240, "total": 1840 }, "meta": { "total_count": 312, "page": 1, "per_page": 1, "total_pages": 312 }}range=all_timecounts everyone still waiting now. Without it the window is the last 30 days, andfrom/to(dates in the shop’s time zone) pick another window.meta.total_countis how many variant rows the export will have;totals.pendingis how many people are waiting across all of them.count_byis echoed back.customerscounts a shopper who signed up by email and SMS for the same variant once; sendcount_by=signupsto count every signup.
2. Page through every row and write the CSV
Section titled “2. Page through every row and write the CSV”Up to 500 rows a page. include_inventory and include_prices add the live stock and price columns (each asks Shopify once per page):
echo "variant_id,product,variant,sku,pending,total,inventory_available,price,last_requested_at" > demand.csvpage=1while :; do body=$(curl -s "https://app.stoqapp.com/api/v2/external/back_in_stock/reports/products_in_demand?range=all_time&sort_by=pending&direction=desc&per_page=500&include_inventory=true&include_prices=true&page=$page" \ -H "X-Auth-Token: $STOQ_API_KEY") echo "$body" | jq -r '.rows[] | [.shopify_variant_id, .product_title, .variant_title, .sku, .pending, .total, .inventory_available, .price, .last_requested_at] | @csv' >> demand.csv [ "$(echo "$body" | jq '.meta.page >= .meta.total_pages')" = "true" ] && break page=$((page + 1))doneEach row:
{ "shopify_variant_id": "gid://shopify/ProductVariant/123", "shopify_product_id": "gid://shopify/Product/456", "variant_title": "Small / Blue", "product_title": "Classic Tee", "sku": "TEE-S-BLU", "image_url": "https://cdn.shopify.com/…", "deleted": false, "inventory_available": 0, "price": "25.00", "compare_at_price": "30.00", "pending": 42, "total": 65, "last_requested_at": "2026-10-09T08:30:00Z"}inventory_available is the stock in the locations the store’s market or location filter allows, null when Shopify has no level for the variant. Narrow the export with vendors, tags or shopify_market_ids (comma-separated), or search (product title or SKU). group_by=product gives one row per product instead.
Over MCP, call execute_read with the same params and a smaller page, then call the next_page each result gives you until there is none. A result is capped at about 25,000 tokens; a cut page is listed under truncated, and next_page carries on from the last row you got, so no row is skipped.
{ "tool": "execute_read", "arguments": { "method": "GET", "path": "/back_in_stock/reports/products_in_demand", "params": { "range": "all_time", "sort_by": "pending", "per_page": 100, "include_inventory": true, "include_prices": true } } }3. Add how long shoppers wait for the top items
Section titled “3. Add how long shoppers wait for the top items”For each of the top variants:
curl "https://app.stoqapp.com/api/v2/external/back_in_stock/reports/wait_duration?shopify_variant_id=123&range=all_time" \ -H "X-Auth-Token: $STOQ_API_KEY"{ "tool": "execute_read", "arguments": { "method": "GET", "path": "/back_in_stock/reports/wait_duration", "params": { "shopify_variant_id": "gid://shopify/ProductVariant/123", "range": "all_time" } } }The answer has median_wait_days, max_wait_days, interval and distribution (the histogram, paid plans; distribution_included_in_plan says whether it is filled in).
4. Optional: what restocks earned before
Section titled “4. Optional: what restocks earned before”GET /back_in_stock/reports/product_revenue ranks products by the revenue back-in-stock alerts brought in, with from/to or range=all_time. Join it to the CSV on shopify_product_id to weigh demand by past conversion.
If it fails
Section titled “If it fails”| Code | What happened | What to do |
|---|---|---|
auth_, auth_ |
No API key, or not a current one | Send the store’s key in X-Auth-Token |
invalid_ |
A filter failed the schema, such as sort_ or a malformed date |
Use a value from expected.; dates are YYYY-MM-DD or ISO 8601 |
rate_ |
The key used its points for this minute | Wait retry_ seconds and carry on from the same page; each page costs 1 point |
shopify_ |
Shopify throttled the stock or price lookup | Retry the same page after retry_ seconds, or leave out include_ / include_ |
upstream_, shopify_ |
A service the page needs didn’t answer | Retry that page with backoff; reads are safe to repeat |
Check it worked
Section titled “Check it worked”demand.csvhasmeta.total_countrows plus the header.- The
pendingcolumn sums tototals.pendingfrom step 1 (with the same filters andcount_by). - The top rows match the dashboard’s Reports → Products in demand table, sorted by Pending, with the same window and market filter.
- Spot-check one variant:
GET /back_in_stock/signups?shopify_variant_id=<id>&status=pendingreturnsmeta.total_countsignups. That is a signup count, so it can be higher than apendingcounted by customers.
Thanks for letting us know.
Still stuck? Ask Quinn or chat with support