n8n Tutorial: Automate a Shop Order Workflow Locally
Quick answer
n8n is a workflow automation tool you host yourself: you connect small steps called nodes into a workflow, and the workflow runs when something happens, like a webhook call or a schedule. This post builds a real one on a laptop: a webhook receives a new shop order, a Code node checks it and adds up the total, an HTTP Request node records it in a file, and a reply node answers the shop. No cloud account, and every step below ran for real, including the two failures.
A small clothing shop in Karachi takes orders over WhatsApp. The owner reads each message, copies the items into a spreadsheet, works out the total, and replies to the customer. It works until it does not: one order copied with the wrong quantity, one total added up wrong, one message answered twice because nobody could tell if it was handled. The shop does not need a new backend service, just the same boring steps done the same way every time. That is the job n8n is built for.
What I would check before using it
My first check is whether the work is really a repeatable chain of steps. n8n fits when the flow is the same every time. If the logic is deeply custom, a small service you write yourself fits better, and the FastAPI Explained: Python APIs at Full Speed post covers that choice.
My second check is where the data lives. Self-hosted n8n keeps everything on your machine, in a local SQLite database by default. There is a hosted n8n Cloud, but it is a subscription.
My third check is how durable the flow has to be. n8n records every run as an execution, and a failed step can be retried. But n8n is orchestration, not a queue: if none of a hundred orders a minute may be lost, a durable queue in front is safer, and the RabbitMQ Tutorial: An Order Queue That Never Loses Work post shows that pattern.
My fourth check is who maintains the workflows. The canvas is visual, but debugging one still means reading JSON and logs. If nobody on the team will own that, a scheduled script may be simpler, and the GitHub Actions Explained: Automation That Runs on Every Push post covers scheduled automation.
My verdict, as judgement: adopt n8n when the same multi-step chore repeats every week. It flips when the logic is custom enough to deserve its own service, or when nobody will maintain the workflows.
A Karachi shop order, from webhook to file
The demo is a small Karachi clothing shop: an order arrives as JSON at a webhook, gets validated and totalled, gets written to a file, and the caller gets a confirmation back.
Install n8n with npm:
$ npm install n8n@1.120.4
added 2033 packages in 8m
$ n8n --version
1.120.4
Start it and open the editor at http://localhost:5678:
$ n8n start
Version: 1.120.4
Editor is now accessible via:
http://localhost:5678
Four nodes. The Webhook node listens for POST requests at /new-order. The Code node validates the order and works out the total. The HTTP Request node sends it to a tiny local receiver on port 4000 that appends each order to orders.jsonl. The Respond to Webhook node sends the confirmation back. The receiver is short:
const http = require("http");
const fs = require("fs");
const path = require("path");
const FILE = path.join(__dirname, "orders.jsonl");
const server = http.createServer((req, res) => {
if (req.method === "POST" && req.url === "/orders") {
let body = "";
req.on("data", (chunk) => (body += chunk));
req.on("end", () => {
const order = JSON.parse(body);
fs.appendFileSync(FILE, JSON.stringify(order) + "\n");
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify({ stored: true, order_id: order.order_id }));
});
return;
}
res.writeHead(404, { "Content-Type": "application/json" });
res.end(JSON.stringify({ error: "not found" }));
});
server.listen(4000, () => {
console.log("orders receiver listening on http://localhost:4000/orders");
});
The Code node does the real checking: it refuses orders with no customer or no items, refuses items with a non-numeric price or quantity, and totals the rest:
const order = $input.first().json.body;
if (!order || typeof order !== 'object') {
throw new Error('Expected a JSON order object in the request body');
}
if (!order.customer) {
throw new Error('Missing field: customer');
}
if (!Array.isArray(order.items) || order.items.length === 0) {
throw new Error('Missing field: items (at least one item required)');
}
let total = 0;
for (const item of order.items) {
if (typeof item.price_rs !== 'number' || typeof item.qty !== 'number') {
throw new Error('Each item needs a numeric price_rs and qty');
}
total += item.price_rs * item.qty;
}
return [{
json: {
order_id: order.order_id || ('ORD-' + Date.now()),
customer: order.customer,
city: order.city || 'Karachi',
items: order.items,
total_rs: total,
status: 'recorded',
received_at: new Date().toISOString()
}
}];
Import the workflow and activate it:
$ n8n import:workflow --input=workflow.json
Importing 1 workflows...
Successfully imported 1 workflow.
$ n8n update:workflow --id=gHBTZOqnYhY7wkb3 --active=true
Activating workflow with ID: gHBTZOqnYhY7wkb3
Activation or deactivation will not take effect if n8n is running.
Please restart n8n for changes to take effect if n8n is currently running.
That warning is the first thing that went wrong: the running server had already loaded its workflows, so the webhook stayed unregistered and the call returned 404:
$ curl -X POST http://localhost:5678/webhook/new-order \
-H 'Content-Type: application/json' \
-d '{"order_id":"ORD-3001","customer":"Ayesha Khan","city":"Karachi","items":[{"name":"White Cotton Kurta","price_rs":2450,"qty":1},{"name":"Pastel Lawn Kurta","price_rs":1950,"qty":2}]}'
{"code":404,"message":"The requested webhook \"POST new-order\" is not registered.","hint":"The workflow must be active for a production URL to run successfully."}
The fix is a restart. The log confirmed it:
$ n8n start
Version: 1.120.4
Start Active Workflows:
Activated workflow "New order intake" (ID: gHBTZOqnYhY7wkb3)
The same order now ran:
$ curl -X POST http://localhost:5678/webhook/new-order \
-H 'Content-Type: application/json' \
-d '{"order_id":"ORD-3001","customer":"Ayesha Khan","city":"Karachi","items":[{"name":"White Cotton Kurta","price_rs":2450,"qty":1},{"name":"Pastel Lawn Kurta","price_rs":1950,"qty":2}]}'
{"status":"received","order_id":"ORD-3001","customer":"Ayesha Khan","total_rs":6350,"stored":true}
Rs 2,450 once plus Rs 1,950 twice is Rs 6,350, and the file got its line:
$ cat orders.jsonl
{"order_id":"ORD-3001","customer":"Ayesha Khan","city":"Karachi","items":[{"name":"White Cotton Kurta","price_rs":2450,"qty":1},{"name":"Pastel Lawn Kurta","price_rs":1950,"qty":2}],"total_rs":6350,"status":"recorded","received_at":"2026-12-01T03:16:05.938Z"}
One more run showed a sharp edge: an order with no items got an empty HTTP 200 back. The failure only showed up in the executions list, marked error with "Error: Missing field: items (at least one item required)". A 200 from n8n means the webhook accepted the request, not that the workflow succeeded.
Common mistakes and how to fix them
First, calling the webhook before the workflow is active. The symptom is a 404 with "The requested webhook \"POST new-order\" is not registered." The fix is to activate the workflow, and restart n8n if you activated it from the command line while it was running.
Second, trusting an empty 200. The symptom is a caller that thinks the order went through, while the execution list shows an error. The fix is to check the executions list after every test, and add an Error Trigger workflow so failures send a real alert.
Third, sending an order with no items or a price as text. The symptom is the Code node error "Missing field: items (at least one item required)" or "Each item needs a numeric price_rs and qty". The fix is to validate at the sender: numbers must arrive as numbers, not as strings like "2450".
Fourth, building the whole flow in the editor and never testing it with a real call. The symptom is a workflow that looks right on the canvas but has a wrong field name or URL. The fix is to trigger it with curl as a shop system would.
Frequently Asked Questions
Do I need Docker or a cloud account to try n8n? No. This whole post ran from an npm install on a laptop.
How is n8n different from a cron job or GitHub Actions? A schedule runs a script at a time; n8n runs a chain of steps when an event happens, passing each result on. The GitHub Actions Explained: Automation That Runs on Every Push post covers scheduled automation, and n8n fits better when the trigger is an event, not a clock.
What happens when a step fails halfway through? The execution stops and is marked as an error, with the message from the failing node. Steps that already ran are not undone, so a workflow that charges a customer and then fails needs a compensation step. The Temporal Tutorial: Shop Orders That Never Get Lost post covers flows that must resume where they stopped.
What to remember
- A workflow is a chain of nodes that runs when a trigger fires.
- A production webhook only answers once the workflow is active; a CLI activation needs a restart.
- Validate early in a Code node, and treat its errors as the contract for senders.
- An empty HTTP 200 means the webhook accepted the request, not that the workflow succeeded.
Where this leaves you
One webhook, one validation step, one file write, and a shop order now travels from a curl call to a recorded line without a person copying anything: ORD-3001, Rs 6,350, stored. The two failures were the useful part, the 404 that taught me activation needs a restart, and the empty 200 that taught me to check the executions list. Take a chore of your own, the kind you repeat by hand every week, and draw it as four boxes before you write any code.
Further reading
- n8n documentation
- Webhook node
- Code node
- GitHub Actions Explained: Automation That Runs on Every Push
- Temporal Tutorial: Shop Orders That Never Get Lost
- RabbitMQ Tutorial: An Order Queue That Never Loses Work
- FastAPI Explained: Python APIs at Full Speed
- WebSockets Explained: Real-Time Data Without Polling
Waqas Shahid is a software engineer from Karachi with more than 12 years of experience, including 6+ years in engineering leadership. He writes The Practical Developer.
Comments
Post a Comment