Smart Inventory Replenishment & Auto-Purchase Orders - n8n Workflow

Automate inventory management using this advanced n8n workflow. It combines real-time stock data, sales velocity, and OpenAI forecasting to automatically create and dispatch purchase orders.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Supply Chain Managers looking to transition from reactive to proactive, AI-driven inventory control.
E-commerce or Retail businesses struggling with stockouts or overstocking issues.
Developers needing robust n8n templates for integrating multiple ERP, warehouse, and AI services.
Technical teams who require a complex, scheduled n8n workflow that performs data merging, advanced logic, and external API communication.

Overview

Inventory management is typically a reactive process, often leading to either expensive stockouts or wasteful overstocking. This sophisticated n8n workflow solves this by introducing predictive intelligence powered by OpenAI.

The automation runs on a set schedule, autonomously gathering data from your warehouse and sales systems. It utilizes a custom n8n node combination, including the powerful OpenAI integration, to generate precise demand forecasts and recommend reorder quantities. If a product crosses the AI-defined reorder threshold, the n8n workflow automatically creates a detailed purchase order (PO), sends it to the relevant supplier via API, logs the transaction in your ERP system, and saves the detailed record (including AI confidence levels) to a database.

This complete solution demonstrates how to use the n8n platform to build critical, scalable business operations, providing a highly efficient alternative to manual procurement processes. It is a perfect example of an AI-automation workflow that drives tangible business value.

How it Works

This n8n workflow operates in five distinct phases, triggered by an hourly schedule:


  1. Scheduled Data Fetch: The process initiates using the Schedule Trigger n8n trigger every six hours. This immediately triggers parallel HTTP requests using the n8n node architecture to fetch current stock levels and recent sales velocity data (30-day velocity).

  2. Data Unification: A Code n8n node efficiently merges the inventory data and sales data based on the shared productid. This creates a comprehensive dataset ready for analysis.

  3. AI Analysis and Forecasting: The merged data is passed to the AI Demand Forecasting n8n node (leveraging OpenAI). The AI analyzes stock levels, sales trends, lead times, and reorder points to determine if replenishment is necessary, providing a concrete recommendation (shouldreorder: true/false) and a recommended_quantity.

  4. Decision and PO Generation: A Filter n8n node checks the AI's recommendation. Only items marked for reorder proceed. A subsequent Code n8n node generates a complete, structured Purchase Order document, calculating costs, setting expected delivery dates, and embedding the AIโ€™s reasoning as notes.

  5. Fulfillment and Logging: The newly created PO is processed through three final actions:

The PO is submitted to the supplier's API via an HTTP Request n8n node.
The transaction is logged into the company's ERP system using another HTTP Request.
The full record is permanently stored in a database (PostgreSQL) using an n8n node.
Finally, the procurement team receives a detailed Send Notification Email about the automatic PO creation.

Installation Guide

To implement this n8n workflow template, follow these steps:


  1. Import the Workflow: Copy the provided JSON data and paste it directly into your n8n instance using the "Import from JSON" option.

  2. Configure Credentials: You must update the credentials for the required services:

OpenAI: Set up your OpenAI API key credentials within n8n.
PostgreSQL/Database: Configure the credentials for your database system (e.g., PostgreSQL credentials).
SMTP: Configure your SMTP credentials to enable the Send Notification Email n8n node.

  1. Update HTTP Request Nodes: This n8n workflow relies on integrating with your existing systems (Warehouse, Sales, ERP, Supplier). For the four HTTP Request n8n nodes:

Replace the placeholder URLs (https://your-warehouse-api.com/...) with your actual API endpoints.
Update the Authorization header bearer tokens/API keys in the parameters of each request.
Adjust the body structure in the Send PO to Supplier and Log to ERP System nodes to match your respective API requirements.

  1. Activate and Monitor: Once all configurations are complete, activate the n8n workflow. The Schedule Trigger n8n trigger will start the inventory check automatically every six hours.

Node Details

This advanced n8n workflow utilizes several key nodes to achieve end-to-end automation:

Schedule Trigger (n8n trigger):
Function: Starts the entire process at predefined intervals.
Key Configuration: Set to run every 6 hours (hoursInterval: 6).
Fetch Current Inventory & Fetch Sales Velocity (HTTP Request n8n node):
Function: Retrieves necessary real-time data from external APIs (Warehouse and Sales/CRM).
Key Configuration: Requires replacement of placeholder URLs and updating Authorization Bearer Tokens in headers. Fetch Sales Velocity uses a query parameter for days: 30.
Merge Inventory & Sales Data (Code n8n node):
Function: Takes two parallel input streams and combines inventory and sales metrics based on productid for AI consumption.
Key Configuration: Contains custom JavaScript logic specifically tailored for this merging operation.
AI Demand Forecasting (OpenAI n8n node):
Function: Uses large language models (GPT-4 recommended) to analyze combined data, forecast future demand, and decide if a reorder is necessary.
Key Configuration: Uses a custom API call to send structured data to the model. Requires valid OpenAI credentials.
Parse AI Response (Code n8n node):
Function: Safely parses the JSON output generated by the AI model, ensuring data integrity and preparing key fields (like should
reorder) for downstream filtering.
Filter: Reorder Needed (Filter n8n node):
Function: Implements core logic flow control by only allowing items where shouldreorder is explicitly true to proceed to the purchase stage.
Create Purchase Order (Code n8n node):
Function: Dynamically constructs the final Purchase Order object, generating a unique PO number, calculating total
cost, and determining the expected_delivery based on the product's lead time.
Send PO to Supplier & Log to ERP System (HTTP Request n8n node):
Function: Handles external API communication to finalize the transaction. One sends the PO to the vendor, the other logs it in the company ERP system.
Key Configuration: Requires customization of body parameters to match specific external vendor/ERP schemas.
Save to Database (Postgres n8n node):
Function: Provides persistent logging of the entire PO and forecast data into a PostgreSQL database via an executeQuery operation.
Send Notification Email (Email Send n8n node):
* Function: Alerts the necessary team members (e.g., procurement) that an automatic PO has been generated by the n8n workflow.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

Featured*