Business tech · Beginner · 20 min
Build your first n8n workflow with a webhook trigger
By Padding · Updated 18 Nov 2026
Node.js 24 LTS · n8n 2.49.7
You will have a published n8n workflow that takes a website enquiry by POST, checks a secret header, rejects enquiries without an email address and answers with JSON.
On this page
Ember Studio, a seven-person design agency with staff in Lagos and Nairobi, gets new work through the enquiry form on its website. Today the form emails whoever happens to be on the shared inbox. You will replace that with an n8n workflow the studio runs itself: the form posts to a webhook, n8n checks the request carries a secret header, drops anything without an email address, tidies the fields, and answers the website with JSON it can show the visitor.
n8n is a workflow tool you can host on your own machine or server. Unlike Zapier or Make, the enquiries never pass through a third party's servers and there is no per-task count to watch: the limits are your server's. The trade-off is that you look after it. n8n is published under its Sustainable Use License, which allows running it for your own business's internal use.
You will build the workflow from a JSON file and drive n8n from its command line, so every step is repeatable, then open the editor to see what you built. Everything runs on localhost in a throwaway folder, ~/n8n-demo, which the last step deletes.
Step 1 · Install n8n in a demo folder
Check your Node.js version first. n8n 2.49.7 needs Node.js 24: the package refuses to start on anything older, and the n8n docs list 24.x as the newest supported release:
node --versionThe output starts with v24.. If it starts with v20. or v22., n8n 2.49.7 will not start; if it starts with v26., it is newer than n8n supports. In either case install Node.js 24 alongside your current version (for example with a version manager), switch to it, and run node --version again before you go on.
Create the folder and install n8n into it rather than globally, so nothing outside the folder changes and removing it later removes everything:
mkdir -p ~/n8n-demo
cd ~/n8n-demo
npm init -y > /dev/null
npm install --no-fund --no-audit n8n@2.49.7The install downloads several hundred megabytes and takes a few minutes. On prepaid mobile data that is worth knowing before you start: run it on Wi-Fi, or once on a server where bandwidth is cheaper.
Now write a small wrapper script. It tells n8n to keep its database, settings and encryption key in ~/n8n-demo/.n8n instead of your home folder, and switches off the usage telemetry and the new-version check:
cat > ~/n8n-demo/n8n.sh <<'SH'
#!/bin/sh
export N8N_USER_FOLDER="$HOME/n8n-demo"
export N8N_DIAGNOSTICS_ENABLED=false
export N8N_VERSION_NOTIFICATIONS_ENABLED=false
exec "$HOME/n8n-demo/node_modules/.bin/n8n" "$@"
SH
chmod +x ~/n8n-demo/n8n.shCheck it worked
~/n8n-demo/n8n.sh --versionThe command prints 2.49.7. This proves the install worked, not that your Node.js version is supported: n8n prints its version before it checks Node.js, so --version succeeds even on Node.js 22. The node --version check above is the one that matters. The n8n docs say installs from npm are deprecated from n8n 3.0, so treat this as a way to learn; for the studio's real instance, use Docker Compose and PostgreSQL.
Step 2 · Create the secret the form will send
Anyone who finds a webhook URL can post to it. Header authentication makes n8n refuse any request that does not carry a header with the right value. The website's server adds the header when it forwards the form, so the secret never appears in the page a visitor downloads.
Generate a random value and save it as a ready-made curl header file. umask 077 makes the file readable only by you from the moment it exists, and the secret never appears on a command line:
cd ~/n8n-demo
umask 077
node -e "process.stdout.write('X-Form-Key: ' + require('node:crypto').randomBytes(24).toString('hex') + '\n')" > form-key.header
umask 022n8n keeps secrets in credentials, stored encrypted in its database. Build a Header Auth credential from the file. The command writes a private, temporary JSON file, imports it, then deletes it:
cd ~/n8n-demo
FORM_KEY=$(sed 's/^X-Form-Key: //' form-key.header)
umask 077
cat > credential.json <<JSON
[
{
"id": "emberFormKey0001",
"name": "Ember enquiry form key",
"type": "httpHeaderAuth",
"data": { "name": "X-Form-Key", "value": "$FORM_KEY" }
}
]
JSON
umask 022
unset FORM_KEY
~/n8n-demo/n8n.sh import:credentials --input=credential.json
rm credential.jsonn8n creates its database and an encryption key the first time any command runs, so the first run takes a little longer. If this command stops with Your Node.js version ... is currently not supported by n8n, you are not on Node.js 24: switch to it and run the block again. The credential's data goes in as plain JSON and n8n encrypts it with that key on import.
Check it worked
The import ends with a line like Successfully imported 1 credential., and the folder now holds the header file and n8n's data folder, but no credential.json:
ls -A ~/n8n-demoYou see .n8n, form-key.header, n8n.sh, node_modules, package-lock.json and package.json.
Step 3 · Write the workflow as JSON
An n8n workflow is a JSON document: a list of nodes, each with a type and parameters, and a map of which node feeds which. This one has five nodes:
- Enquiry form (Webhook): listens for
POST /enquiries, checks the header credential, and waits for a Respond to Webhook node to answer. - Has an email? (If): passes the enquiry on only when the
emailfield is not empty and contains@. Everything else goes to the false branch. - Shape enquiry (Edit Fields, also called Set): keeps only the fields the studio wants, trims the text, lowercases the email and stamps the time it arrived.
- Thank the sender (Respond to Webhook): answers
200with a JSON message the website can show. - Reject: no email (Respond to Webhook): answers
422with an error the form can display.
Write the file:
cat > ~/n8n-demo/enquiries.json <<'JSON'
{
"id": "emberEnquiries01",
"name": "Ember Studio website enquiries",
"active": false,
"settings": { "executionOrder": "v1" },
"nodes": [
{
"id": "6f1c2a3e-8b4d-4c1a-9e2f-0a1b2c3d4e01",
"name": "Enquiry form",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [0, 0],
"webhookId": "0b7d5c9a-3e2f-4a61-8d1c-5f4e3a2b1c01",
"parameters": {
"httpMethod": "POST",
"path": "enquiries",
"authentication": "headerAuth",
"responseMode": "responseNode",
"options": {}
},
"credentials": {
"httpHeaderAuth": { "id": "emberFormKey0001", "name": "Ember enquiry form key" }
}
},
{
"id": "6f1c2a3e-8b4d-4c1a-9e2f-0a1b2c3d4e02",
"name": "Has an email?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [220, 0],
"parameters": {
"conditions": {
"options": { "caseSensitive": true, "leftValue": "", "typeValidation": "strict", "version": 2 },
"conditions": [
{
"id": "c1a2b3c4-0000-4000-8000-000000000001",
"leftValue": "={{ ($json.body.email ?? '').toString().trim() }}",
"rightValue": "",
"operator": { "type": "string", "operation": "notEmpty", "singleValue": true }
},
{
"id": "c1a2b3c4-0000-4000-8000-000000000002",
"leftValue": "={{ ($json.body.email ?? '').toString() }}",
"rightValue": "@",
"operator": { "type": "string", "operation": "contains" }
}
],
"combinator": "and"
},
"options": {}
}
},
{
"id": "6f1c2a3e-8b4d-4c1a-9e2f-0a1b2c3d4e03",
"name": "Shape enquiry",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [440, -100],
"parameters": {
"mode": "manual",
"assignments": {
"assignments": [
{ "id": "a0000000-0000-4000-8000-000000000001", "name": "name", "type": "string", "value": "={{ ($json.body.name ?? '').toString().trim() }}" },
{ "id": "a0000000-0000-4000-8000-000000000002", "name": "email", "type": "string", "value": "={{ $json.body.email.toString().trim().toLowerCase() }}" },
{ "id": "a0000000-0000-4000-8000-000000000003", "name": "message", "type": "string", "value": "={{ ($json.body.message ?? '').toString().trim() }}" },
{ "id": "a0000000-0000-4000-8000-000000000004", "name": "receivedAt", "type": "string", "value": "={{ $now.toISO() }}" }
]
},
"options": {}
}
},
{
"id": "6f1c2a3e-8b4d-4c1a-9e2f-0a1b2c3d4e04",
"name": "Thank the sender",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [660, -100],
"parameters": {
"respondWith": "json",
"responseBody": "={{ { ok: true, message: 'Thanks ' + $json.name + ', we will reply within one working day.', email: $json.email } }}",
"options": { "responseCode": 200 }
}
},
{
"id": "6f1c2a3e-8b4d-4c1a-9e2f-0a1b2c3d4e05",
"name": "Reject: no email",
"type": "n8n-nodes-base.respondToWebhook",
"typeVersion": 1.1,
"position": [440, 100],
"parameters": {
"respondWith": "json",
"responseBody": "={{ { ok: false, error: 'Please include an email address.' } }}",
"options": { "responseCode": 422 }
}
}
],
"connections": {
"Enquiry form": { "main": [[{ "node": "Has an email?", "type": "main", "index": 0 }]] },
"Has an email?": {
"main": [
[{ "node": "Shape enquiry", "type": "main", "index": 0 }],
[{ "node": "Reject: no email", "type": "main", "index": 0 }]
]
},
"Shape enquiry": { "main": [[{ "node": "Thank the sender", "type": "main", "index": 0 }]] }
},
"pinData": {}
}
JSONA few things to notice:
- Values starting with
=are expressions.{{ $json.body.email }}reads theemailfield from the request body the Webhook node received. The Webhook node puts the parsed body underbody, next toheadersandquery. ?? ''turns a missing field into an empty string, so a form that leaves out a field is rejected by the If node rather than breaking the workflow.- The Webhook node names the credential by
idandname. It holds no secret itself, so this file is safe to keep in version control or share with a colleague. - In
connections, the If node's first list is the true branch and the second is the false branch.
Check it worked
Ask Node.js to parse the file and count the nodes:
node -e "const w = require(process.env.HOME + '/n8n-demo/enquiries.json'); console.log(w.nodes.length, w.nodes.map(n => n.name).join(' | '))"It prints 5 Enquiry form | Has an email? | Shape enquiry | Thank the sender | Reject: no email. A typo in the JSON shows up here as a SyntaxError with a position, which is easier to fix now than after import.
Step 4 · Import and publish the workflow
Import the file, then list the workflows n8n knows about:
cd ~/n8n-demo
~/n8n-demo/n8n.sh import:workflow --input=enquiries.json
~/n8n-demo/n8n.sh list:workflowImported workflows always arrive unpublished. Since n8n 2.0, a workflow you edit is a draft, and publishing makes the current draft the live version that answers production webhooks. Publish it by its ID:
~/n8n-demo/n8n.sh publish:workflow --id=emberEnquiries01publish:workflow runs the same checks as the Publish button in the editor, such as a clash with another workflow's webhook path, and prints the reason if a check fails.
Check it worked
list:workflow printed emberEnquiries01|Ember Studio website enquiries, and listing only published workflows now shows it too:
~/n8n-demo/n8n.sh list:workflow --active=trueThe output includes emberEnquiries01|Ember Studio website enquiries.
Step 5 · Start n8n and open the editor
In your second terminal, start n8n and leave it running:
~/n8n-demo/n8n.sh startAfter a short wait it prints something like Editor is now accessible via: http://localhost:5678. Because the workflow was published before n8n started, n8n registers its production webhook as it starts up. If you publish while n8n is running, it picks the change up within about 15 seconds.
Open http://localhost:5678 in a browser. The first visit asks you to set up the owner account: an email address, a name and a password. This account owns everything in the instance, including the workflow and credential you imported, so use a real password and keep it in your password manager.
If n8n runs on a remote server rather than your own computer, do not open port 5678 to the internet. From your computer, run ssh -L 5678:localhost:5678 you@your-server (replace you@your-server with your login) and open http://localhost:5678 in your local browser.
Check it worked
From your first terminal, the health check answers:
curl -s http://localhost:5678/healthzIt prints {"status":"ok"}. In the browser, the Overview page lists Ember Studio website enquiries marked as published. Open it and you see the five nodes on the canvas, with the If node splitting into two Respond to Webhook nodes. Open the Enquiry form node: Authentication shows Header Auth with the Ember enquiry form key credential selected.
Step 6 · Send enquiries with curl
Production webhooks live at /webhook/<path>. Send a complete enquiry with the secret header. -H @file reads the header from the private file, so the secret stays off the command line. -w adds the status code on its own line after the body:
curl -s -w '\n%{http_code}\n' -X POST http://localhost:5678/webhook/enquiries \
-H @"$HOME/n8n-demo/form-key.header" \
-H 'Content-Type: application/json' \
-d '{"name": "Wanjirũ Kamau", "email": " Wanjiru@Example.com ", "message": "We need a new identity for a clinic in Nairobi."}'Now send one with no email address:
curl -s -w '\n%{http_code}\n' -X POST http://localhost:5678/webhook/enquiries \
-H @"$HOME/n8n-demo/form-key.header" \
-H 'Content-Type: application/json' \
-d '{"name": "Tunde", "message": "Call me back"}'And one without the secret header, as a stranger who found the URL would:
curl -s -w '\n%{http_code}\n' -X POST http://localhost:5678/webhook/enquiries \
-H 'Content-Type: application/json' \
-d '{"name": "Bot", "email": "bot@example.com", "message": "Buy followers"}'Check it worked
- The complete enquiry returns
{"ok":true,"message":"Thanks Wanjirũ Kamau, we will reply within one working day.","email":"wanjiru@example.com"}and200. The email is trimmed and lowercased, and the name with its tilde arrives intact: n8n handles text as UTF-8, so names in Gĩkũyũ, Yorùbá or Amharic need no special treatment. - The enquiry without an email returns
{"ok":false,"error":"Please include an email address."}and422. - The request without the header returns
Authorization data is wrong!and403. n8n refuses it before any node runs.
A website form that posts as application/x-www-form-urlencoded works too: the Webhook node parses those fields into body in the same way.
Step 7 · Compare the test URL and read the execution history
Every Webhook node has two URLs. The production URL, /webhook/enquiries, answers whenever the workflow is published, and n8n does not show its data on the canvas. The test URL, /webhook-test/enquiries, only exists while you are watching in the editor. Call it now, with nobody listening:
curl -s -o /dev/null -w '%{http_code}\n' -X POST http://localhost:5678/webhook-test/enquiries \
-H @"$HOME/n8n-demo/form-key.header"It prints 404, because no test webhook is registered. In the editor, open the Enquiry form node, choose the Test URL tab and select Listen for test event. For the next 120 seconds the test URL is live: run the complete-enquiry curl command again with webhook-test in place of webhook, and the canvas fills with the data each node received and produced. Use the test URL while you change the workflow, then publish again so the production URL runs your new version.
Production runs are kept in the workflow's Executions tab. Open it: the two production requests that reached the workflow are listed, one ending at Thank the sender and one at Reject: no email. If you called the test URL while Listen for test event was on, that run is listed too, marked as a manual (test) execution, because n8n saves manual executions by default. Select one to see every node's input and output, which is where you start when a website owner tells you an enquiry went missing. The request without the header is not listed, because n8n turned it away before the workflow started.
Check it worked
The test URL returned 404 while nobody was listening, and the Executions tab shows two production executions for Ember Studio website enquiries, ending at Thank the sender and Reject: no email, each with a green success mark. A third entry marked as a manual or test execution is your test URL run. Opening the first shows wanjiru@example.com in the output of Shape enquiry.
Step 8 · Clean up
When you have finished, stop n8n with Ctrl+C in the second terminal. It can take a few seconds to shut down cleanly.
The next command deletes the demo folder, including n8n's database, its encryption key, the workflow, the credential and the header file. Export anything you want to keep first, for example with ~/n8n-demo/n8n.sh export:workflow --id=emberEnquiries01 --output=$HOME/enquiries-backup.json.
cd ~
rm -rf ~/n8n-demoCheck it worked
ls ~/n8n-demo reports that there is no such file or directory, and http://localhost:5678 no longer loads.
Next steps
- Run the studio's real instance on a server, behind HTTPS, with PostgreSQL: self-host n8n with Docker Compose.
- Protect what you build there: back up and update a self-hosted n8n.
- A shared header proves the caller knows a secret; a signature also proves the body was not changed. See how that works in verify webhook signatures in Node.js.
- Compare the hosted approach: automate a repetitive task with Zapier.
Related tutorials
- Self-host n8n with Docker Compose and PostgreSQLYou will run n8n 2.49 and PostgreSQL 18 from one compose.yaml on your own server, with secrets in a private env file, HTTPS through Caddy and an owner account ready for your first workflow.
- Back up and update a self-hosted n8nYou will back up a self-hosted n8n 2.49 instance (workflow and credential exports, a database dump and the encryption key), prove the backup by restoring it on a fresh instance, then update the pinned image tag with a rollback plan ready.
- Write a privacy notice for a small business websiteYou will turn your data inventory into a plain-language privacy notice that names every tool you use, meets the transparency lists in the GDPR, Nigeria's Data Protection Act and South Africa's POPIA, and is linked from every form on your site.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials