Webhook - modify response code based on criteria

Would be nice to change the response code of a webhook based on some business logic criteria. For example:

  • If an entry with some id already exists, webhook should return http 400
  • If an entry with some id does not exist, insert the record into the database and return http 200

Thanks

Hey @GaRe!

Welcome to the community :slightly_smiling_face:

You can send a custom response based on your business logic. To do that select ‘Last Node’ from the Response Mode dropdown. This will send the data that is returned by the last node in the workflow. You can use the Set node to set this response.

Hope this helps!

Hey,

First of all, thanks for your reply. I know I can modify the response body (JSON). I would also like to change the “Response code” based on some business logic criteria.
Response code can’t be changed dynamically and node always returns the value defined in the WenHook node settings (for example 200)

Thanks for the further information. Now I have a clear idea of what exactly you mean. Yes, currently this is not possible. I too believe this can be a helpful feature.

A PR for a very basic version got created:

Can get tested via this docker command:

docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n:PR-2254-webhook-response-node

Is still wip, no work went into the node-design and got also not properly tested yet. If anybody wants to give it a try anyway to see if it would allow all use cases and works properly you are very welcome. So is obviously also feedback and bug reports.

2 Likes