Skip to content

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.

  • 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: curl and jq for 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.
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_time counts everyone still waiting now. Without it the window is the last 30 days, and from/to (dates in the shop’s time zone) pick another window.
  • meta.total_count is how many variant rows the export will have; totals.pending is how many people are waiting across all of them.
  • count_by is echoed back. customers counts a shopper who signed up by email and SMS for the same variant once; send count_by=signups to 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.csv
page=1
while :; 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))
done

Each 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).

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.

Code What happened What to do
auth_required, auth_invalid No API key, or not a current one Send the store’s key in X-Auth-Token
invalid_params A filter failed the schema, such as sort_by=revenue or a malformed date Use a value from expected.enum; dates are YYYY-MM-DD or ISO 8601
rate_limited The key used its points for this minute Wait retry_after seconds and carry on from the same page; each page costs 1 point
shopify_rate_limited Shopify throttled the stock or price lookup Retry the same page after retry_after seconds, or leave out include_inventory / include_prices
upstream_unavailable, shopify_error A service the page needs didn’t answer Retry that page with backoff; reads are safe to repeat
  1. demand.csv has meta.total_count rows plus the header.
  2. The pending column sums to totals.pending from step 1 (with the same filters and count_by).
  3. The top rows match the dashboard’s Reports → Products in demand table, sorted by Pending, with the same window and market filter.
  4. Spot-check one variant: GET /back_in_stock/signups?shopify_variant_id=<id>&status=pending returns meta.total_count signups. That is a signup count, so it can be higher than a pending counted by customers.
Was this page helpful?

Still stuck? Ask Quinn or chat with support