This n8n workflow automates the monitoring of warehouse inventory and sales velocity to predict demand, generate purchase orders automatically, send them to suppliers, and record all transactions in ERP and database systems. It uses AI-driven forecasting to ensure timely restocking while maintaining operational efficiency and minimizing stockouts or overstocking.
Key Features
- Automated Scheduling: Periodically checks inventory and sales data at defined intervals.
- Real-Time Data Fetching: Retrieves live warehouse stock levels and sales trends.
- AI Demand Forecasting: Uses OpenAI GPT to predict future demand based on sales velocity and stock trends.
- Auto-Purchase Orders: Automatically generates and sends purchase orders to suppliers.
- ERP Integration: Logs completed purchase orders into ERP systems like SAP, Oracle, or Netsuite.
- Database Logging: Saves purchase order details and forecast confidence data into SQL databases (PostgreSQL/MySQL).
- Email Notifications: Notifies relevant teams upon successful order creation and logging.
- Modular Configuration: Each node includes configuration notes and credentials setup instructions.
Workflow Process
-
Schedule Trigger
- Runs every 6 hours to monitor stock and sales data.
- Interval can be adjusted for higher or lower frequency checks.
-
Fetch Current Inventory Data
- Retrieves live inventory levels from the warehouse API endpoint.
- Requires API credentials and optional GET/POST method setup.
-
Fetch Sales Velocity
- Pulls recent sales data for forecasting analysis.
- Used later for AI-based trend prediction.
-
Merge Inventory & Sales Data
- Combines inventory and sales datasets into a unified JSON structure.
- Prepares data for AI model input.
-
AI Demand Forecasting
- Sends merged data to OpenAI GPT for demand prediction.
- Returns demand score, reorder need, and confidence levels.
-
Parse AI Response
- Extracts and structures forecast results.
- Combines AI data with original inventory dataset.
-
Filter: Reorder Needed
- Identifies items flagged for reorder based on AI output.
- Passes only reorder-required products to next steps.
-
Create Purchase Order
- Automatically creates a PO document with item details, quantity, and supplier information.
- Calculates total cost and applies forecast-based reorder logic.
-
Send PO to Supplier
- Sends the generated purchase order to supplier API endpoints.
- Includes response validation for order success/failure.
-
Log to ERP System
- Records confirmed purchase orders into ERP platforms (SAP, Oracle, Netsuite).
- Includes timestamps and forecast metrics.
-
Save to Database
- Stores all PO data, supplier responses, and AI forecast metrics into PostgreSQL/MySQL tables.
- Useful for long-term audit and analytics.
-
Send Notification Email
- Sends summary emails upon PO creation and logging.
- Includes PO ID, supplier, cost, and demand reasoning.
Setup Instructions
Industries That Benefit
This automation is highly beneficial for:
- Retail & E-commerce: Predicts product demand and auto-orders from suppliers.
- Manufacturing: Ensures raw materials are restocked based on production cycles.
- Pharmaceuticals: Maintains optimum inventory for high-demand medicines.
- FMCG & Supply Chain: Balances fast-moving goods availability with minimal overstocking.
- Automotive & Electronics: Prevents delays due to missing components.
Prerequisites
- API access to inventory, sales, supplier, and ERP systems.
- Valid OpenAI API key for demand forecasting.
- SQL database (PostgreSQL/MySQL) for record storage.
- SMTP or mail server credentials for email notifications.
- n8n environment with required nodes installed (HTTP, AI, Filter, Email, Database).
Modification Options
- Change forecast logic or thresholds for different industries.
- Integrate Slack/Teams for live notifications.
- Add approval workflow before sending POs.
- Extend AI prompt for seasonality or promotional trends.
- Add dashboard visualization using Grafana or Google Sheets.
Explore More AI Workflows:
Get in touch with us to build industry-grade n8n automations with predictive intelligence.