Quick overview
This workflow receives new order webhooks, uses OpenAI to plan and execute inventory reservations across multiple stores via HTTP APIs, logs allocation decisions to Postgres, and either auto-confirms the order in an OMS or requests a manual approval in Slack for partial/failed fulfillment.
How it works
- Receives a POST webhook for a new order containing the order ID, customer ID, line items, and optional candidate stores.
- Builds an order-scoped idempotency key and checks Postgres to ignore duplicate deliveries for orders that were already processed.
- Uses an OpenAI agent with HTTP tools to check per-store stock, respect rate limits, reserve inventory idempotently, and release reservations when a multi-store plan must be rolled back.
- Parses the agent’s JSON output and logs the allocation plan, reservations, verdict, and any shortfalls to Postgres for audit.
- If the agent verdict is to confirm, sends the allocation plan to the OMS confirmation endpoint to auto-confirm the order.
- If the order needs review, posts a shortfall summary and allocation details to a Slack channel, waits for an ops decision, and then confirms or cancels the order via the OMS API.
Setup
- Create Postgres tables (for example,
inventory_orders and inventory_reservations) and add Postgres credentials, then update table/schema names if your database differs.
- Add an OpenAI credential and ensure the selected chat model (gpt-4.1) is available in your OpenAI account.
- Configure the inventory middleware/store API endpoints and authentication used by the HTTP tools that check stock, create reservations, release reservations, and read rate-limit status.
- Add Slack credentials and set (or create) the target channel (for example,
#inventory-ops-review) for manual review notifications.
- Update the OMS API base URL and authentication in the HTTP request nodes for order confirm/cancel, and copy the webhook URL from n8n into your order source system to send new-order events.
- If you use the built-in manual resolution step, share its resume webhook URL with your ops tooling so it can post
opsApproved=true/false to continue the workflow.