Webhook Redirection and Delayed Responses

I’ve been playing with webhooks and realized that in addition to the on received and last node responses, it would be convenient to provide a redirect function. This would be particularly helpful when receiving form submissions as the hook could then redirect the user to a confirmation page.

Currently I’m working with static sites and using n8n for contact form submissions. I need to implement some javascript to perform an ajax form submission and redirection. (with or without processing the return value) It would be much more streamlined to simply post forms to a n8n webhook and have the client redirected by n8n.

Additionally, while significantly more complex, delayed responses would be interesting.

  1. Receive webhook and process data
  2. Run through an IF block
  3. Send webhook response based on IF conditions, or even a secondary node’s actions. (eg SMTP fails)
  4. Complete the webhook response, returning (or redirecting) based on above logic.

Yes, can see how that could be helpful! At least the first part. Can you please explain the second one with the “delayed responses”. I do sadly not totally understand that especially because it seems to sends two responses. Once in 3 and once in 4.

Sorry, you’re correct. To clarify:

  1. Receive an incoming webhook, collect any (post/etc) data, leave the connection open if possible (think long polling)
  2. Move to other nodes such as IF, an API call, etc
  3. Webhook Response node: Handle and return/close the connection from number 1 based on info passed by anything in number 2.

As long as there aren’t timeout issues I think this would work. Receive the request, leave connection open until any future node resolves it.

Ah in that case you are describing what can be done with a Webhook Trigger-Node in Response Mode: “Last Node”.

Here an example:
https://n8n.io/workflows/3

Oh, well that makes sense now. I saw that and thought “Last Node” meant previous. Come to think about it that doesn’t make sense for a trigger…

So if that works as I expect it does, that resolves the second part of my request.

Is redirection something that can be (easily) done?

A secondary feature would be to redirect based on the Last Node as well. Rather than returning, if you use a Last Node Redirect, the last node would simply return the URL to be used for the redirection.

Eg:
Webhook: Last Node Redirect (takes web site form submission)
Node: Send Email
If Successful: Return confirmation url for Last Node Redirect
Else: Return error url for Last Node Redirect

Ah great that at least one problem you have is solved!

About the redirect. I have to think a little bit about how I can implement that in a “good way”. Will update here if I came up with something. Sadly do not know how fast that will be.