n8n Webhook Tutorial: Receive External Data in Your Workflows
February 2, 2025 ยท 8 min read
Webhooks are the backbone of real-time automation. Instead of polling APIs every few minutes, webhooks let external services push data to your n8n workflow the instant something happens.
This guide walks you through setting up webhooks in n8n โ from the basic trigger node to production-ready patterns with authentication, error handling, and response customization.
What Is a Webhook?
A webhook is an HTTP endpoint that waits for incoming requests. When another service sends data to that URL, your workflow triggers immediately.
Think of it as a doorbell: instead of checking if someone's at the door every 5 minutes (polling), you wait for the bell to ring (webhook).
Common webhook use cases:
- Stripe sends a payment event โ n8n processes the order
- GitHub push โ n8n runs deployment pipeline
- Form submission โ n8n saves to database + sends email
- Slack command โ n8n runs AI analysis and replies
Step 1: Add the Webhook Trigger Node
In n8n, create a new workflow and add a Webhook node as the trigger (first node).
// Webhook node settings
HTTP Method: POST
Path: /my-webhook
Response Mode: Last Node
The Path becomes part of your webhook URL. With a path of /my-webhook, your full URL will be something like:
Step 2: Test with a Sample Request
Before connecting a real service, test your webhook manually. Click "Listen for Test Event" in n8n, then send a test request:
# Using curl
curl -X POST https://your-n8n.com/webhook-test/my-webhook \
-H "Content-Type: application/json" \
-d '{"name": "Test User", "email": "test@example.com"}'
n8n should show the received data in the webhook node output. You can now use{{ $json.name }} and{{ $json.email }} in downstream nodes.
โ ๏ธ Test vs Production URLs
n8n has two webhook URLs: /webhook-test/ (only works while you're testing in the editor) and /webhook/ (works when the workflow is active). Use the production URL when configuring external services.
Step 3: Process the Data
After the webhook receives data, add nodes to process it. Here's a common pattern:
- Webhook โ receives the incoming data
- IF node โ validate the data (check required fields exist)
- Set node โ transform/rename fields as needed
- Action node โ save to database, send email, call API, etc.
- Respond to Webhook โ send a response back to the caller
Step 4: Add Authentication
In production, you don't want anyone to trigger your webhook. n8n supports several auth methods:
Header Authentication
Set a secret header that callers must include:
// Webhook node โ Authentication
Authentication: Header Auth
Header Name: X-Webhook-Secret
Header Value: your-secret-token-here
Any request without the correct header gets rejected with a 403.
HMAC Signature Verification
For services like GitHub and Stripe that sign webhook payloads, use an IF node or Code node to verify the HMAC signature before processing.
Step 5: Handle Errors Gracefully
Webhooks in production will receive malformed data, duplicate events, and unexpected payloads. Build for it:
- Validate early: Check required fields in the first node after the webhook
- Respond fast: Many services timeout after 5-30 seconds. Acknowledge receipt quickly, then process asynchronously if needed
- Handle duplicates: Some services send the same event multiple times. Use an ID field to deduplicate
- Log failures: Use the Error Trigger node to catch and log any workflow failures
Step 6: Customize Your Response
With Response Mode: Last Node, whatever your final "Respond to Webhook" node outputs becomes the HTTP response. This is powerful:
// Respond to Webhook node
Response Code: 200
Response Body:
{
"status": "received",
"id": "{{ $json.processedId }}",
"message": "Event processed successfully"
}
Production Checklist
- โ Use the production webhook URL (not test)
- โ Workflow is active (toggle in top-right)
- โ Authentication is configured
- โ Input validation on required fields
- โ Error handling with Error Trigger node
- โ Response is returned quickly (<5 seconds)
- โ Duplicate event handling (idempotency)
- โ HTTPS enabled (don't accept webhooks over plain HTTP)
Common Gotchas
- Webhook not receiving data? Make sure the workflow is active (green toggle). Test URLs only work during editor testing.
- Getting empty body? Check the Content-Type header. n8n expects
application/jsonfor JSON parsing. - Timeout errors? If your workflow takes >30 seconds, set Response Mode to "Immediately" to acknowledge receipt first.
- Webhook URL changes after restart? Self-hosted n8n regenerates webhook URLs unless you set a fixed path. Always use a custom path, not the auto-generated one.
Next Steps
Now that you have webhooks working, you can build powerful real-time automations. Check out our workflow templates for production-ready examples, or read our guide on connecting n8n to AI with MCP servers.
Want pre-built webhook workflows?
Our Pro templates include production-ready webhook patterns with authentication, error handling, and AI processing built in.
View Pro Templates โ