Build a AI Inventory Manager — Demand Forecast & Reorder Alerts for Shopify/WooCommerce Workflow with n8n

Every ecommerce operator knows the two failure modes of inventory: too much cash frozen in dead stock, or a bestseller stocked out during peak demand. Both are expensive, and both come from the same r

Build a AI Inventory Manager — Demand Forecast & Reorder Alerts for Shopify/WooCommerce Workflow with n8n

Every ecommerce operator knows the two failure modes of inventory: too much cash frozen in dead stock, or a bestseller stocked out during peak demand. Both are expensive, and both come from the same root cause — you are reacting to inventory levels instead of forecasting them. By the time your Shopify dashboard shows "3 units left," the reorder is already late. Suppliers have lead times of 2 to 6 weeks. If you notice the shortage the day it happens, you have already lost the sale.

This article walks through a working n8n workflow that fixes that. It runs every morning at 7am, pulls 90 days of order history from Shopify or WooCommerce, uses GPT-4o to forecast the next four weeks of demand per SKU, flags every product that will run out before a new order can arrive, and emails your ops team while there is still time to act. No dashboards to check, no spreadsheets to maintain. Here is exactly how it is built.

The problem: reorder points are static, demand is not

Most stores set a fixed reorder threshold — "reorder when we hit 20 units." That number is wrong the moment you set it, because it assumes constant demand. A product selling 2 per day and a product selling 15 per day have wildly different runway at 20 units: 10 days versus barely one. A single reorder point cannot capture that, and it certainly cannot capture seasonality, a viral spike, or the slow decay of a fading product.

The manual alternative is a weekly spreadsheet where someone exports orders, builds a velocity column, subtracts current stock, and eyeballs the risk. It works until the catalog grows past 50 SKUs, someone goes on vacation, or the export gets skipped for two weeks. The failure is silent — you only discover it when a customer tries to buy something you cannot ship. What you actually need is a per-SKU, forward-looking runway calculation that runs on its own and only speaks up when there is a real risk. That is a workflow, not a dashboard.

The solution: a daily forecast-and-alert loop

The workflow is a single linear pipeline in n8n with six stages:

  • Schedule Trigger — fires daily at 07:00 in your timezone.
  • Fetch orders — pulls the last 90 days of orders from Shopify or WooCommerce.
  • Aggregate by SKU — a Code node reshapes raw line items into per-product sales velocity.
  • Fetch current stock — grabs live inventory levels for the same products.
  • GPT-4o forecast — the model projects 4-week demand and flags at-risk SKUs.
  • Filter + Email — only products that will stock out before reorder lands get sent to ops.

The intelligence sits in the GPT-4o step, but the reliability comes from the plumbing around it. The model never sees raw JSON dumps — it sees clean, pre-aggregated numbers, which is what makes the forecast accurate and cheap. Let us build it.

Step-by-step setup in n8n

1. Schedule Trigger. Add a Schedule Trigger node. Set the interval to "Days," value 1, and trigger at hour 7. Confirm the workflow's timezone under Settings → matches your operation, not UTC — a 7am UTC run is 2am in New York and useless for your team.

2. Pull order history. For Shopify, use the Shopify node (or an HTTP Request node against /admin/api/2024-01/orders.json) with status=any, created_at_min set to 90 days ago, and fields=line_items,created_at. Enable pagination — Shopify caps at 250 orders per page, so loop on the Link header or use the node's built-in "Return All." For WooCommerce, use the WooCommerce node, resource Order, with an after date filter of 90 days. Compute the date dynamically with an expression: {{ $now.minus({ days: 90 }).toISO() }}.

3. Aggregate by SKU. Add a Code node. Loop every order's line items, group by SKU, and total quantity sold. Divide by 90 to get daily velocity, and keep the last-14-day total separately so the model can see whether demand is accelerating:

const sales = {};
for (const item of $input.all()) {
  for (const li of item.json.line_items) {
    const s = sales[li.sku] ??= { sku: li.sku, name: li.name, qty90: 0, qty14: 0 };
    s.qty90 += li.quantity;
    const days = $now.diff($fromISO(item.json.created_at), 'days').days;
    if (days <= 14) s.qty14 += li.quantity;
  }
}
return Object.values(sales).map(s => ({ json: {
  ...s, velocity_day: +(s.qty90 / 90).toFixed(2)
}}));

4. Attach current stock. Add another Shopify/WooCommerce call (or a Merge node keyed on SKU) to bring in live inventory_quantity per product. Include your average supplier lead time in days as a static field — put it in a Set node (e.g. 21 days) or pull it per-product if you track it. The forecast is meaningless without lead time; it is the whole point of "before the next reorder arrives."

5. GPT-4o forecast. Add the OpenAI node (Chat model, gpt-4o). Feed it the aggregated array as JSON and use a system prompt that forces structured output:

You are an inventory analyst. For each product you receive
{sku, velocity_day, qty14, qty90, stock, lead_time_days}.
Project demand for the next 28 days, accounting for whether
the 14-day rate is above or below the 90-day rate (trend).
Compute days_of_stock = stock / projected_daily.
Flag risk=true when days_of_stock < lead_time_days + 7.
Return ONLY JSON: [{sku, projected_28d, days_of_stock, risk, reason}]

Set temperature to 0 for deterministic math and enable JSON mode / "Output Content as JSON." The +7 buffer gives your team a week of slack to actually place the order. GPT-4o handles the trend adjustment — a naive velocity average would miss a product whose sales doubled in the last two weeks.

6. Filter and email. Add an IF or Filter node keeping only items where risk === true. If the list is empty, the workflow ends silently — no noise on healthy days. When there are at-risk SKUs, pass them to a Code node that builds an HTML table (SKU, current stock, days of runway, reason), then a Send Email, Gmail, or Slack node to your ops channel. Sort the table by days-of-stock ascending so the most urgent product is at the top.

What this actually buys you

The benefit is not "AI in your stack" — it is turning inventory from a reactive fire drill into a scheduled, forward-looking task. Concretely:

  • You reorder on runway, not on gut. Every alert already accounts for lead time, so the reorder goes out with a week to spare instead of a week too late.
  • Silence means healthy. Because the workflow only emails on real risk, an empty inbox is a positive signal, not a gap in monitoring. Your team stops checking a dashboard nobody reads.
  • Trend-aware, not average-blind. The 14-day-versus-90-day comparison catches products that are heating up or cooling down — the exact SKUs a static reorder point gets wrong.
  • It scales for free. Whether you have 40 SKUs or 4,000, the run cost is a few cents of GPT-4o tokens and thirty seconds of compute. No extra headcount as the catalog grows.

Common pitfalls (and how to avoid them)

Feeding raw order JSON to GPT-4o. The single biggest mistake. If you skip the aggregation Code node and dump 90 days of orders into the prompt, you blow the context window, pay 50x the tokens, and get worse forecasts. Always pre-compute velocity in n8n; let the model do the projection, not the arithmetic of summing.

Ignoring pagination. Shopify and WooCommerce both cap results per page. A store doing more than 250 orders in 90 days will silently get a truncated history and under-forecast demand. Verify your fetch returns the full window — log the order count and sanity-check it against your real volume.

Forgetting lead time. "Days of stock" alone is not actionable. A product with 10 days of runway is fine if your supplier ships in 3 days and a crisis if they ship in 21. The lead-time field is what converts a number into a decision. Set a sensible default and refine it per supplier over time.

Non-deterministic output. Leaving temperature at the default causes the model to occasionally return prose instead of JSON, breaking the downstream Filter node. Pin temperature to 0, enable JSON mode, and add a small error branch that alerts you if parsing fails so a bad run never passes silently.

Alerting on everything. If you email the full forecast every day, your team will filter it to trash within a week. Send only the at-risk subset, sorted by urgency. The discipline of "only speak when it matters" is what keeps the workflow trusted six months in.

Build this once and inventory stops being something you watch and becomes something that watches itself — quietly, every morning at 7am, warning you while there is still time to act.

AI Inventory Manager — Demand Forecast & Reorder Alerts for Shopify/WooCommerce
PRONTO PARA USAR

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 →