How to Automate AI Inventory Manager — Demand Forecast & Reorder Alerts for Shopify/WooCommerce with n8n
Every ecommerce operation loses money in two directions at once: cash frozen in overstock that won't sell for months, and revenue evaporating every time a bestseller hits zero inventory. The second on
Every ecommerce operation loses money in two directions at once: cash frozen in overstock that won't sell for months, and revenue evaporating every time a bestseller hits zero inventory. The second one is worse. A stockout on a high-velocity SKU doesn't just cost you that sale — it pushes the customer to a competitor, tanks your product ranking, and trains your best buyers to look elsewhere. Most teams "manage" this with a spreadsheet someone updates on Fridays and a gut feeling about what's moving. That works until you have more than about 40 SKUs, at which point no human can hold demand curves, lead times, and reorder points in their head across the whole catalog.
This article shows you how to build an automated inventory manager in n8n that runs every morning, uses GPT-4o to forecast demand from your real order history, and emails your ops team a ranked list of exactly what to reorder before it runs out — no dashboards to check, no manual math.
The problem with reactive inventory management
Manual reorder logic almost always relies on a fixed threshold: "when stock drops below 20, order more." That single number ignores everything that actually determines whether you'll stock out. It ignores velocity (a SKU selling 5/day and one selling 5/week both trip the same alert), it ignores seasonality and trend (last month's rate is useless going into a promo or a holiday spike), and it ignores lead time (if your supplier takes 21 days, a threshold of 20 units on a product selling 3/day means you're already too late the moment the alert fires).
The result is a business that's simultaneously over- and under-stocked. You've got 400 units of a slow mover tying up working capital, and you're out of the product that drives 30% of revenue. Reactive thresholds can't fix this because the question isn't "how much is left?" — it's "will this run out before a replacement can physically arrive?" Answering that requires forecasting, and forecasting across a full catalog by hand is exactly the kind of repetitive, high-stakes calculation you should never assign to a human.
The solution: a daily forecasting workflow
The workflow is a single n8n automation that fires once a day at 7am, before your team starts. Its logic in plain terms:
- Pull the last 90 days of orders from Shopify or WooCommerce.
- Aggregate sales per SKU into a daily velocity series.
- Pass that history to GPT-4o with each product's current stock level and supplier lead time.
- Have the model forecast demand for the next 4 weeks and flag every product that will hit zero before a reorder placed today could arrive.
- Email operations a prioritized reorder list — SKU, days-until-stockout, recommended order quantity, and a one-line rationale.
GPT-4o is doing the part that's hard to hard-code: it reads the trend, distinguishes a genuine acceleration from a one-day spike, and reasons about the gap between "days of stock left" and "days until resupply." You're not asking it to be a magic oracle — you're giving it clean numbers and a tight, structured question, which is where LLM forecasting on small-to-medium catalogs actually performs well.
Step-by-step setup in n8n
1. Schedule Trigger. Add a Schedule Trigger node set to a cron expression of 0 7 * * *. This runs the workflow daily at 07:00 in your instance timezone (set the timezone under the workflow settings, not the node, to avoid the classic UTC drift).
2. Fetch order history. For Shopify, use the Shopify node with operation Get All Orders, filtered to created_at_min = 90 days ago and status=any. For WooCommerce, use the WooCommerce node, Get All Orders, with an after date parameter. If your store is large, turn on pagination and set Return All to true so you don't silently truncate at 250 records — a partial history quietly corrupts every forecast downstream.
3. Fetch current inventory. Add a second store node (Get All Products / product variants) to pull each SKU's current inventory_quantity. This is your "how much is left right now" baseline. Merge it with the order data on SKU using a Merge node in Combine → Merge By Fields mode.
4. Aggregate into daily velocity. Use a Code node (JavaScript) to reduce raw line items into a per-SKU object: total units sold, a 90-element daily quantity array, and the current stock. Keep the payload lean — send the model aggregated series, not thousands of raw order rows. A useful shape per SKU: { sku, name, current_stock, lead_time_days, daily_units: [...], units_90d, units_30d, units_7d }. Attach lead time from a static map or a column in your product metafields.
5. Forecast with GPT-4o. Add the OpenAI node (or the AI Agent / Basic LLM Chain node) with model gpt-4o. Set the temperature low — 0.2 — because you want deterministic arithmetic reasoning, not creativity. Your system prompt should be explicit:
"You are an inventory forecasting engine. For each SKU you receive daily sales for the last 90 days, current stock, and supplier lead time in days. Forecast expected demand for the next 28 days accounting for recent trend. Return only products where projected cumulative demand exceeds current stock before (today + lead_time_days). Respond as strict JSON: an array of { sku, days_until_stockout, forecast_28d, recommended_reorder_qty, reason }. Order the array by days_until_stockout ascending. If no product is at risk, return []."
Turn on JSON mode (Response Format: JSON) so the output is machine-parseable. Batch SKUs into groups of ~30–50 per call to stay well inside the context window and keep each response reliable; a Loop Over Items (Split In Batches) node handles this cleanly.
6. Parse and guard. Follow with a Code node that parses the JSON and filters out anything with days_until_stockout above your planning horizon. Add an IF node: if the risk list is empty, end silently (no "all clear" email — nobody wants a daily nothing-to-do message).
7. Email the team. Use the Send Email (SMTP) or Gmail node. Build an HTML table in a Code node from the risk array — one row per at-risk SKU, sorted most-urgent first, with days-until-stockout in red for anything under the lead time. Subject line like ⚠️ 6 products need reordering — 2 critical so the urgency is visible before the email is even opened.
Benefits you feel within a week
Stockouts become rare and predictable. Because the trigger is "will run out before resupply arrives" rather than a static number, you get warned with enough runway to actually act. The lead-time-aware logic is the whole point — it converts inventory management from firefighting into a scheduled, boring routine.
Working capital stops leaking into overstock. The same forecast that flags stockouts implicitly tells you what not to reorder. Slow movers never appear on the list, so you stop reflexively restocking things that sit.
Zero daily overhead. The workflow runs at 7am and either sends a short, ranked action list or stays silent. Your ops team reads one email and places orders — no spreadsheet, no dashboard-checking, no per-SKU mental math. On a 200-SKU catalog that's easily an hour a day of skilled labor returned.
It scales with the catalog, not against it. Adding SKUs costs nothing — the batching loop absorbs them. The system that saves you an hour at 50 products saves you most of a role at 500.
Common pitfalls (and how to avoid them)
Truncated order history. The single most common failure: pagination left off, so the workflow silently forecasts on the most recent 250 orders and under-predicts everything. Always set Return All and spot-check the item count on your first runs.
Feeding raw orders to the model. Dumping thousands of line items into the prompt blows the context window, costs more, and degrades accuracy. Aggregate to per-SKU daily series in a Code node before the LLM. The model should reason over clean numbers, not parse your order feed.
No lead-time data. Without each supplier's lead time, the model can only guess at "before resupply arrives" and the whole value proposition collapses. If you don't have precise numbers, use a conservative default (e.g. 21 days) and refine per supplier over time — a rough lead time beats none.
Non-deterministic output. High temperature or no JSON mode produces prose the downstream nodes can't parse, and the email breaks. Pin temperature to 0.2 and enforce JSON response format. Add a try/catch in the parse node so one malformed batch never kills the whole run.
Ignoring new products. A SKU with 10 days of history has no reliable trend. Flag anything under ~14 days of sales as "insufficient data — manual review" instead of letting the model hallucinate a forecast from noise.
Alert fatigue. If you email even when nothing's at risk, the team stops reading. Keep the IF-node silence rule: no alert on an empty list. The email should always mean "act now," never "just so you know."
Build it once and it earns its keep every single morning — quietly protecting revenue on your bestsellers and freeing cash from the shelves. The wiring above is entirely standard n8n; the only genuinely hard part is the forecasting prompt and the lead-time-aware risk logic, both of which are already solved in the ready-made template below.
Ja construimos isso pra voce
Nao comece do zero. O AI Inventory Manager — Demand Forecast & Reorder Alerts for Shopify/WooCommerce e um workflow n8n pronto para instalar — conecta suas ferramentas em minutos, sem codigo.
Instalar por $199 →