Why does HTTP Requests loop substitute query params only once?

Hello! I am new to n8n, some things are not obvious to me. I searched for an answer to my question, but did not find it. I would be grateful for any useful links and detailed explanations.

Describe the issue/error/question

I am preparing some data at the beginning of the workflow. They end up in the query string when requested. Several queries are executed and the query string must be inserted into each of them. In fact, QS are substituted only in the first request, the rest are ignored.

I could prepare all the urls manually, but that doesn’t seem like the right way. What is the right way to complete my task?

Please share the workflow

Share the output returned by the last node

Actual query params:

[
  {
    "hello": "hello",
    "q": "1",
    "world": "world"
  },
  {
    "q": "2"
  }
]

Expected query params:

[
  {
    "hello": "hello",
    "q": "1",
    "world": "world"
  },
  {
    "hello": "hello",
    "q": "2",
    "world": "world"
  }
]

Information on your n8n setup

  • n8n version: 0.177.0
  • Database you’re using (default: SQLite): postgresql
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm

Hey @melodyn,

Welcome to the community :rocket:

It looks like this is going to be down to the way the data is looped, So your first node has 1 output item but the node before the HTTP Request node has 2 outputs. This means the HTTP Request node is running twice but because of the internal looping it is attemping to look the first node twice as well to get the second but of data but it can’t find anything.

If you change the request to use {{$items("BuildQuery")[0].json["hello"]}} it will always use the first output item rather than trying to be clever. The example below should do what you are after.

1 Like

Thanks, this helped me! Such solutions are often non-intuitive, if there were more examples for nodes it would be great :slight_smile:

1 Like

We are working on making improvements to our documentation but we are also working on coming up with some new workflow templates that might help with some of these requests.

1 Like