How to use "Respond to webhook" while providing a previous step's output? (object, not array)

Describe the problem/error/question

I want to return one of the previous Node’s output. How do I do that?

N8n wraps everything under arrays and weird wrappers, simple programming stuff becomes hard because it’s unintuitive and not clear how to get the raw data we want.

One (dumb) way that works:

Returning the full json returns plenty of n8n internal stuff we don’t want:

How to simply get the object returned by a previous step and return that, without any wrapping around?

What is the error message (if any)?

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Use a merge node to get the data from the node you want.
There is an option to choose the branch and then you can simply just select the one you need.
image

Thank you for taking the time to reply.

I must say, this is so highly counter-intuitive.

I have the data, I can see them, and yet I need to use some kind of complex/unnecessary merging mechanism to merge nothing in order to achieve the end-result?

Surely, there is a simpler/straighter way to achieve that, is there not?

It is how n8n works.
A node is triggered by the incoming data, you can directly use that data. If you want to use other data you need to reference it specifically.

Might be good to do the course to get a better feeling of how it works.

Which course do you have in mind?

There are 2 playlists on YouTube. Beginner and advance. Besides of this. If I see it right, you want to have the output of “pipedrive update org’s name…” as respond for the webhook? if you connect the webhook respond node to the node and also the other pipedrive node, it should work? Please keep in mind, n8n works from left to right, from top to bottom.

1 Like

You mean I could respond earlier than I currently do?

If I connect multiple nodes to the “Respond to webhook”, what will happen?
Will it respond immediately after that node is reached? (I assume it will)
Or will it wait to execute all nodes connected to the “Respond to webhook”? I doubt so.

This might indeed work, although it’s not what I want to do in most cases, as it might make believe the webhook worked fine, but it could fail to actually update the data in Pipedrive.

Typically, if any node after “Compute new Org name” fails and the “Respond to webhook” is placed after it, then the webhook HTTP response will be 200 regardless of the error. That’s not really a good practice, as it will essentially hide the error and make it harder to debug.

So far, none of the answers provided are simple to implement.
If I just want to return a previous node’s output, I believe it’s just simpler to have my “Compute new Org name” also return a “JSON-friendly” property, and use that as JSON in “Respond to Webhook” node.

Surely the simplest solution, although I wish there would be a better way to do that.

There are multiple ways to return the previous node data. What I meant:

You can connect the code node or the other nodes depending on which data you need to the “respond to webhook node” (can use split out/set data) before to just respond the ID or any other data. If there is an error in the path above the response to webhook, the workflow will stop and won’t respond // throw error 500. (like mentioned, n8n is working from left to right top to bottom).

Or, as you mentioned in your post, reference through the expression line.

Or use a merge node. There are multiple ways to use previous node data.

2 Likes

Thanks for the reply.

Can you elaborate a bit on that? I made some quick search but it’s the first time I’m hearing about it. You make it sound like it’s an important detail.
I was aware of “left to right”, that much is rather obvious.
But “top to bottom” is less obvious.

In you workflow above, do you mean the order is:

  1. Webhook
  2. Code
  3. Edit Fields
  4. HTTP Request
  5. Respond to Webhook

I was under the belief that the step 3 and 5 would start at the same time (in parallel), but you make it sound like it won’t.

In this same scenario, what happens if I add another “Respond to Webhook” after “HTTP Request”? Will the one below be ignored then? :thinking:

As for my initial issue, I went the way of the JSON (string) generated by code, much simpler.

Hello, here is a short test workflow.

5 Items at the top (first executed)


5 Items at the bottom

I hope it is clear. The nodes are at the exact x position. :slight_smile:

The best is to just play around a bit. It is important to know this, especially for more complex workflows. To be 100% correct, it is Top to Bottom, Left To Right. Like reading a book :slight_smile:

1 Like

Okay, so it is not running in parallel like I thought, but in series.

And I also guess only the first “Respond to Webhook” reached is actually useful, others won’t have any effect.

image

Here, the “Respond to Webhook” at the top will always be executed first, and the one below will never truly send data back to the browser. It’s essentially useless and should be removed to avoid creating misunderstandings in how this behaves.

Thank you very much for clarifying that part. :+1:

It does depend on the workflow. If you have some if/switch nodes, multiple respond to webhook could make sense.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.