Skip to main content
0 reactions

How to Send a Custom Response from an n8n Webhook

Card titled Send a Custom Webhook Response, labelled n8n webhooks, showing a webhook node linked to a reply node and three facts: GET /hello?name=Asha, Respond With: JSON, and the JSON reply with the greeting Hello, Asha!

By default, an n8n webhook answers every call with {"message":"Workflow was started"}. To send a custom response from an n8n webhook instead, such as a greeting, a result or a saved ID, you add a Respond to Webhook node and tell the Webhook node to wait for it.

This post shows it with a tiny example of its own, a Greeting workflow: call /hello?name=Asha and it answers {"greeting":"Hello, Asha!"}, with the name taken from the call.

Cost: free. Everything here runs on your own n8n Community Edition.

Every command, screen and output on this page is real, run with n8n 2 in Docker on macOS.

Step 1: Make the Webhook Wait for Your Response

Create a new workflow named Greeting, click Add first step and choose On webhook call. In the Webhook node, keep HTTP Method at GET, set Path to hello, and set Respond to Using ‘Respond to Webhook’ Node:

Webhook node settings with HTTP Method GET, Path hello, Authentication None and Respond set to Using ‘Respond to Webhook’ Node, with a note to insert a Respond to Webhook node.
Respond now waits for a Respond to Webhook node.

Now n8n doesn’t answer the caller straight away: it waits for a Respond to Webhook node, as the note under the field says.

Step 2: Add a Respond to Webhook Node

Close the node, click + on the right of the Webhook node, search for Respond to Webhook and choose it. Open its Respond With list and choose JSON:

The Respond With list of the Respond to Webhook node opened, showing All Incoming Items, Binary File, First Incoming Item, JSON and JWT Token, with First Incoming Item selected.
Pick JSON to write your own reply.

Hover over Response Body, click Expression, and replace the sample with:

Response Body (Expression)JSON
{
  "greeting": "Hello, {{ $json.query.name }}!"
}

{{ $json.query.name }} is an n8n expression: it reads name from the call’s query string, the part of the address after ?. In Expression mode, n8n fills it in for every call:

Respond to Webhook settings with Respond With set to JSON and the Response Body in Expression mode, holding a greeting field built from $json.query.name.
The reply reads the name from the address.

Step 3: Test the Custom Response

Close the node and click Execute workflow, so the Test URL waits for one call (Test URL vs Production URL explains the two addresses). Then call it from Terminal (press ⌘ Space, type Terminal and press Return):

TerminalBash
curl "http://localhost:5678/webhook-test/hello?name=Asha"

The quotes stop zsh, the shell in macOS Terminal, from reading ? as a wildcard. n8n answers with your JSON:

OutputPlain text
{"greeting":"Hello, Asha!"}

Both nodes turn green on the canvas:

The Greeting workflow on the canvas after a test call: the Webhook and Respond to Webhook nodes both ticked green, with 1 item passed between them.
Both nodes ran for the test call.

When the reply is right, publish the workflow and give callers its Production URL instead.

Clean Up

If you published the Greeting workflow, unpublish it first. Then archive and delete it from its ⋯ menu. Deleting it can’t be undone.

Common Mistakes

MistakeWhat happensDo this instead
Leaving the Webhook’s Respond at ImmediatelyThe call fails with Unused Respond to Webhook node found in the workflowSet Respond to Using ‘Respond to Webhook’ Node
Calling without ?name=The greeting comes back as Hello, !Add ?name= and a name to the address
Leaving the address unquoted in Terminalzsh stops with no matches foundPut the address in double quotes

Troubleshooting

ProblemCauseFix
{"code":0,"message":"Unused Respond to Webhook node found in the workflow"}, and in the editor Problem in node ‘Webhook‘The Webhook node’s Respond isn’t set to use the Respond to Webhook nodeSet Respond to Using ‘Respond to Webhook’ Node
zsh says no matches found and curl doesn’t runThe address isn’t in quotes, so zsh reads ? as a wildcardPut the address in double quotes

FAQ

What else can Respond to Webhook send?

Its Respond With list also has All Incoming Items, Binary File, First Incoming Item, JWT Token, No Data, Redirect and Text. n8n’s Respond to Webhook docs (opens in a new tab) explain each one.

Can I set the HTTP status code?

Yes. n8n’s docs list a Response Code option under Add option in the Respond to Webhook node, next to Response Headers.

Conclusion

Set the Webhook’s Respond to Using ‘Respond to Webhook’ Node, add a Respond to Webhook node, and build the reply with an expression. Every caller then gets your own answer instead of “Workflow was started”.

Additional Resources

n8n and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by n8n GmbH.

0 comments