Variables passed in the URL are not always initialized in bulk HTTP requests

Hello n8n community,

I stumbled upon a problem with the “HTTP request” node. When handling bulk HTTP requests with a URL that is based on a variable, the first request is correctly performed (meaning the variable is present in the URL); however, in all the subsequent calls the variable “disappears” from the URL. Could you please look into that ? I have attached the workflow as well as the requests sent. If you need more information, please let me know :wink:

I am attaching the log from the HTTP request node. As you can notice, during the first request, the URL is correctly set up (with the id: ~42242240), but this is not the case of the second request.

    REQUEST {
        headers: { accept: 'application/json,text/*;q=0.99' },
        method: 'GET',
        uri: 'https://www.google.com/id/~42242240',
        gzip: true,
        rejectUnauthorized: true,
        json: true,
        callback: [Function: RP$callback],
        transform: undefined,
        simple: true,
        resolveWithFullResponse: false,
        transform2xxOnly: false
    }
    REQUEST {
        headers: { accept: 'application/json,text/*;q=0.99' },
        method: 'GET',
        uri: 'https://www.google.com/id/',
        gzip: true,
        rejectUnauthorized: true,
        json: true,
        callback: [Function: RP$callback],
        transform: undefined,
        simple: true,
        resolveWithFullResponse: false,
        transform2xxOnly: false
    }

And this is the workflow

    {
      "name": "PoC",
      "nodes": [
        {
          "parameters": {},
          "name": "Start",
          "type": "n8n-nodes-base.start",
          "typeVersion": 1,
          "position": [
            250,
            300
          ]
        },
        {
          "parameters": {
            "functionCode": "return [{\"json\": {\"_id\": \"~42242240\"}}];"
          },
          "name": "Function",
          "type": "n8n-nodes-base.function",
          "typeVersion": 1,
          "position": [
            450,
            300
          ]
        },
        {
          "parameters": {
            "functionCode": "return [{\"json\":\n{\n  \"message\": \"hello\"\n}},\n{\"json\":{\n\"message\": \"byebye\"\n}\n}];"
          },
          "name": "GetDocuments",
          "type": "n8n-nodes-base.function",
          "typeVersion": 1,
          "position": [
            620,
            300
          ]
        },
        {
          "parameters": {
            "url": "=https://www.google.com/id/{{$node[\"Function\"].json[\"_id\"]}}",
            "options": {}
          },
          "name": "HTTP Request",
          "type": "n8n-nodes-base.httpRequest",
          "typeVersion": 1,
          "position": [
            810,
            300
          ]
        }
      ],
      "connections": {
        "Start": {
          "main": [
            [
              {
                "node": "Function",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Function": {
          "main": [
            [
              {
                "node": "GetDocuments",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "GetDocuments": {
          "main": [
            [
              {
                "node": "HTTP Request",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      },
      "active": false,
      "settings": {},
      "id": "2"
    }

Best regards,
Laurent

Hey @laurent!

Do you want to make request to the same ID for both the documents? In the example that you shared, there is only one ID, and there is no mapping between the document and the ID.

Assuming that the question to @harshil1712 answer is “yes” you would have to change the expression:

{{$node["Function"].json["_id"]}} 

to

{{$item(0).$node["Function"].json["_id"]}}

That will then make sure to always use the id of the first item and not the id of the corresponding item (which would be for the second item, the second item of the Function node which does not exist as the Function-Node has only one item).

Hope that makes sense!

The following syntax worked for me, thank you jan :wink: