AutomationFlowsTutorials › How to use webhooks in n8n

How to use webhooks in n8n

This tutorial guides you through implementing webhooks in n8n, from setting up triggers to handling responses securely. It's aimed at technical users familiar with n8n basics who want precise steps for building webhook-driven automations.

Why this matters

Webhooks enable real-time data flows in n8n without constant polling, reducing API costs and latency—essential for responsive automations like instant notifications or event-driven integrations. Misconfiguring them often leads to missed triggers or security vulnerabilities, such as exposing endpoints to unauthorised access, which this tutorial helps you avoid by focusing on setup and debugging practices.

Step-by-step

  1. Open your n8n instance and create a new workflow. In the canvas, click the '+' button to add a node, search for Webhook, and select the n8n-nodes-base.webhook trigger node. This sets up the entry point for incoming HTTP requests.
  2. Configure the Webhook node: Set the HTTP Method to POST (common for data payloads) or GET as needed. Under Path, enter a custom route like my-automation-trigger—n8n will generate a full URL like https://your-instance.app/webhook/my-automation-trigger.
  3. Enable Respond in the Webhook node to control the HTTP response. Choose Immediately for a quick 200 OK, or When Last Node Finishes to send a custom response after processing—useful for confirming receipt to the sender.
  4. Add security: Toggle Authentication to Header Auth and set a secret token, e.g., X-Webhook-Secret: your-secret-key. This verifies incoming requests; later nodes can check the header with an IF node using {{ $json.headers['x-webhook-secret'] }}.
  5. Test the webhook: Save and activate the workflow. Copy the generated URL from the Webhook node's output panel. Use a tool like curl to send a test request: curl -X POST https://your-instance.app/webhook/my-automation-trigger -H "Content-Type: application/json" -d '{"test": "data"}'. Expect a success response if configured correctly.
  6. Handle the payload: Connect a Set node after the Webhook to process data. For example, extract JSON with {{ $json.body.test }} and assign it to a new field. This prepares data for downstream nodes like HTTP Request or Email.
  7. Customise the path for multiple webhooks: In the Webhook node, enable Custom Path and use parameters like user/:id. Access params in expressions as {{ $json.params.id }} for dynamic routing within one workflow.
  8. Debug issues: If no trigger fires, check the Executions tab for errors. Use the Test URL (inactive mode) for safe testing without activating. Monitor logs in the Webhook node for request details, including headers and body.
  9. Secure production: Once tested, add an IF node to validate payloads (e.g., check for required keys) and return a 400 error via Respond to Webhook node if invalid. Deploy with HTTPS enabled on your n8n instance.

Worked example

Consider a common pattern: automating GitHub issue notifications. The workflow starts with a Webhook trigger listening on /github-issue for POST requests from GitHub's webhook settings. When a new issue is opened, GitHub sends a JSON payload with details like issue.title and issue.body.

After the Webhook node, connect a Set node to extract key fields: set title to {{ $json.issue.title }} and url to {{ $json.issue.html_url }}. Next, add an IF node to filter by labels—e.g., proceed only if priority: high is present in {{ $json.issue.labels }}.

If true, route to a Slack node (using n8n-nodes-base.slack) to post a message: New high-priority issue: {{ $json.title }} - {{ $json.url }} in your team's channel. Finally, a Respond to Webhook node sends { "status": "notified" } back to GitHub. End-to-end, this triggers instantly on issue creation, processes in seconds, and confirms success without polling.

Common pitfalls

Related workflows in the catalog

Explore n8n's workflow catalog for ready-made examples, like the "GitHub Webhook to Slack" template, which imports directly and demonstrates payload handling. With over 14,000+ importable workflows, search for "webhook" to find integrations such as Stripe payment notifications or Discord bot triggers.

These can be customised quickly—start with one, tweak the Webhook path, and add your auth secrets to fit your setup.