/n8n-tutorials

How to test a webhook in n8n?

Learn how to test a webhook in n8n by creating and configuring a workflow, activating the webhook, and verifying it with tools like cURL or Postman for seamless integration and troubleshooting.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to test a webhook in n8n?

To test a webhook in n8n, you'll need to create a workflow that uses the Webhook node to receive incoming HTTP requests, configure the webhook settings, deploy the workflow, and then trigger the webhook from an external source to verify it's working correctly. The process involves setting up proper request methods, handling authentication if needed, and testing the data flow through your workflow.

 

Step 1: Launch n8n and Create a New Workflow

 

First, you need to access your n8n instance and create a new workflow where you'll test your webhook.


# Access n8n via your browser
http://localhost:5678  # if running locally
# or your custom domain if hosted elsewhere

Once you're in the n8n interface:

  • Click on "Workflows" in the left sidebar
  • Click the "+ Create Workflow" button in the top-right corner
  • Give your workflow a meaningful name like "Webhook Test"
  • Click "Save" to create the workflow

 

Step 2: Add a Webhook Node to Your Workflow

 

Now, you need to add a Webhook node that will listen for incoming HTTP requests:

  • Click the "+" button in the top-right corner of the workflow editor
  • Search for "Webhook" in the node search bar
  • Select the "Webhook" node to add it to your workflow

 

Step 3: Configure the Webhook Node

 

After adding the Webhook node, you'll need to configure it properly:

  • Double-click on the Webhook node to open its settings
  • Set the "Authentication" method if needed (None, Basic Auth, Header Auth, etc.)
  • Choose the HTTP Method(s) you want to accept (GET, POST, PUT, DELETE, etc.)
  • Set the webhook path (e.g., "/my-test-hook")
  • Configure any additional options as needed
  • Click "Execute Node" to activate the webhook

Here's an example configuration for a basic webhook:


Authentication: None
HTTP Method: POST
Path: /my-test-webhook
Respond: Immediately
Response Code: 200
Response Data: Last Node

 

Step 4: Add Processing Nodes (Optional)

 

You can add additional nodes to process the webhook data:

  • Click the "+" button after the Webhook node
  • Search for and add nodes like "Set", "Function", or any integration you want to test
  • Configure these nodes to process the data received from the webhook

For example, you might add a "Set" node to transform the incoming data:


// Example configuration for a Set node
Keep Only Set: False
Values to Set:
- processedData: ={{$json.data}}
- receivedAt: ={{$now.toISOString()}}
- source: "webhook-test"

 

Step 5: Activate and Deploy Your Webhook

 

Now that your webhook is configured, you need to activate it:

  • Click the "Save" button in the top-right corner to save your workflow
  • Toggle the "Active" switch in the top-right corner to activate the workflow
  • Once activated, n8n will display the full webhook URL

Your webhook URL will look something like:


https://your-n8n-instance.com/webhook/path-to-your-webhook
# or for local testing
http://localhost:5678/webhook/path-to-your-webhook

Copy this URL as you'll need it for testing.

 

Step 6: Test the Webhook Using cURL

 

You can test your webhook using cURL from the command line:


# For a simple GET request
curl https://your-n8n-instance.com/webhook/path-to-your-webhook

# For a POST request with JSON data
curl -X POST \\
  -H "Content-Type: application/json" \\
  -d '{"key":"value","test":"data"}' \\
  https://your-n8n-instance.com/webhook/path-to-your-webhook

 

Step 7: Test the Webhook Using Postman

 

Alternatively, you can use Postman for a more visual testing experience:

  • Open Postman
  • Create a new request
  • Select the HTTP method (GET, POST, etc.) that matches your webhook configuration
  • Enter your webhook URL
  • If using POST, go to the "Body" tab, select "raw" and "JSON", and enter your test data
  • Click "Send" to trigger the webhook

Example JSON body for testing:


{
  "customer": {
    "id": 12345,
    "name": "Test Customer",
    "email": "[email protected]"
  },
  "action": "purchase",
  "amount": 99.99
}

 

Step 8: Test with the n8n Test Webhook Node

 

n8n also provides a special "Test Webhook" node that can help test your webhook flow:

  • Create a separate workflow
  • Add a "Manual Trigger" node as the start
  • Add a "HTTP Request" node after it
  • Configure the HTTP Request node to send data to your webhook URL

HTTP Request node configuration example:


Authentication: None
Request Method: POST
URL: https://your-n8n-instance.com/webhook/path-to-your-webhook
Body Content Type: JSON
JSON/RAW: 
{
  "test": true,
  "message": "This is a test from n8n",
  "timestamp": "{{$now}}"
}

 

Step 9: Verify Webhook Execution in n8n

 

After triggering the webhook, you should verify that it executed correctly:

  • Go back to your webhook workflow in n8n
  • Check the "Executions" tab at the bottom of the screen
  • You should see a recent execution with the data that was sent
  • Click on the execution to view the detailed input/output at each node

 

Step 10: Troubleshooting Common Issues

 

If your webhook isn't working as expected, check these common issues:

  • Verify that your workflow is activated (the toggle switch should be "on")
  • Check that you're using the correct HTTP method (GET vs POST)
  • Ensure your webhook URL is correctly formatted
  • Verify that any authentication parameters are correct
  • Check for network/firewall issues if testing from external sources
  • Look at the execution logs for error messages

For CORS-related issues when testing from a browser:


// In the Webhook node settings, enable CORS
Options:
  Allow CORS: true
  Response Headers:
    Access-Control-Allow-Origin: \*
    Access-Control-Allow-Methods: GET,POST,OPTIONS
    Access-Control-Allow-Headers: Content-Type,Authorization

 

Step 11: Testing Webhooks with Authentication

 

If your webhook requires authentication, you'll need to include the appropriate credentials:

  • Basic Auth: Configure the webhook node with username/password
  • Header Auth: Set up a custom header (like an API key)
  • OAuth: Configure the necessary OAuth settings

Example of testing a webhook with Basic Auth using cURL:


curl -X POST \\
  -H "Content-Type: application/json" \\
  -u "username:password" \\
  -d '{"key":"value"}' \\
  https://your-n8n-instance.com/webhook/path-to-your-webhook

Example of testing with an API key:


curl -X POST \\
  -H "Content-Type: application/json" \\
  -H "X-API-Key: your-api-key-here" \\
  -d '{"key":"value"}' \\
  https://your-n8n-instance.com/webhook/path-to-your-webhook

 

Step 12: Testing Webhooks from External Services

 

To test your webhook with external services, you'll need to make your n8n instance publicly accessible:

  • If running locally, you can use a tunneling service like ngrok
  • For production, ensure your n8n instance is properly hosted with a public URL
  • Configure the external service to send data to your webhook URL

Using ngrok for local testing:


# Install ngrok
npm install -g ngrok

# Start ngrok tunnel to your local n8n instance
ngrok http 5678

# Use the generated URL for your webhook
# Example: https://a1b2c3d4.ngrok.io/webhook/path-to-your-webhook

 

Step 13: Setting Up Webhook Timeout and Retry Logic

 

For more robust webhook handling, configure timeout and retry settings:

  • In the Webhook node settings, adjust the "Timeout" value
  • Add error handling nodes to manage failed executions
  • Consider using the "Error Trigger" node for catching webhook failures

Example of webhook settings with timeout:


Authentication: None
HTTP Method: POST
Path: /my-test-webhook
Response Mode: Last Node
Timeout: 30000  # 30 seconds timeout

 

Step 14: Monitoring Webhook Activity

 

To monitor your webhook's activity over time:

  • Use the "Executions" history to view all triggered webhooks
  • Add logging nodes to your workflow to record webhook activities
  • Consider setting up email or Slack notifications for important webhook events

Example of adding a logging node:


// Function node for logging
const timestamp = new Date().toISOString();
const logEntry = {
  event: "webhook\_received",
  timestamp: timestamp,
  data: $json,
  source\_ip: $node["Webhook"].json.headers['x-forwarded-for'] || 'unknown'
};

// Log to file or database
return {json: logEntry};

 

Step 15: Creating a Webhook Response

 

You can customize what your webhook returns to the caller:

  • In the Webhook node settings, set "Response Mode" to "Respond with data"
  • Add a "Set" node to define the response data
  • Configure the response status code and headers

Example of a custom webhook response:


// Set node configuration for webhook response
Keep Only Set: True
Values to Set:
- status: "success"
- message: "Webhook received successfully"
- id: ={{$workflow.id}}
- receivedAt: ={{$now.toISOString()}}

 

Conclusion

 

Testing webhooks in n8n involves setting up a Webhook node, configuring it properly, activating the workflow, and then sending HTTP requests to the generated webhook URL. By following these steps, you can ensure your webhooks are working correctly and integrate smoothly with external services. Remember to consider security, error handling, and monitoring for production webhooks. n8n's visual interface makes it easy to debug and troubleshoot any issues that may arise during webhook testing.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022