Web Request node evaluates variables to null after first run

Describe the issue/error/question

The Web Request node ignores the SET value after 1st execution… Am I missing something very obvious?

I am setting a client name through the initial SET value, which is a placeholder for a future webhook trigger. it will be a single value for the duration of the flow.

at some point I get multiple items in my data, in the final node, web request, I have used the SET node value, but all iterations except first act as if the SET value is null.

What is the error message (if any)?

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "clientName",
              "value": "xxx"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        490,
        290
      ]
    },
    {
      "parameters": {
        "extractionValues": {
          "values": [
            {
              "key": "text",
              "cssSelector": "p",
              "returnArray": true
            }
          ]
        },
        "options": {}
      },
      "name": "HTML Extract",
      "type": "n8n-nodes-base.htmlExtract",
      "typeVersion": 1,
      "position": [
        900,
        290
      ]
    },
    {
      "parameters": {
        "functionCode": "return items[0].json.text.map(text => { return { json: { text } } });\nreturn items;"
      },
      "name": "Split-Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1050,
        290
      ]
    },
    {
      "parameters": {
        "functionCode": "items[0].json.data = `<html>\n   <head>\n   </head>\n   <body>\n      <p>Para 1</p>\n      <p>Para 2</p>\n      <p>Para ...</p>\n      <p>Updated: 21 July 2020</p>\n   </body>\n<html>`;\nreturn items;"
      },
      "name": "Mock Input-Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        750,
        290
      ]
    },
    {
      "parameters": {
        "url": "=https://webhook.site/0531729b-ad0b-497e-b52b-e22f7ca74557?q={{$node[\"Set\"].json[\"clientName\"]}}",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "test",
              "value": "={{$node[\"Set\"].json[\"clientName\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1250,
        290
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Mock Input-Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract": {
      "main": [
        [
          {
            "node": "Split-Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split-Data": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mock Input-Data": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Share the output returned by the last node

1st execution calls https://webhook.site/0531729b-ad0b-497e-b52b-e22f7ca74557?q=xxx&test=xxx
2nd execution calls https://webhook.site/0531729b-ad0b-497e-b52b-e22f7ca74557?q=
3rd execution calls https://webhook.site/0531729b-ad0b-497e-b52b-e22f7ca74557?q=
and all following executions call the same

Information on your n8n setup

  • n8n version: 0.149.0
  • Database you’re using (default: SQLite): PostGreSQL
  • Running n8n with the execution process [own(default), main]: own
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: npm

In the HTTP node. Change {{$node["Set"].json["clientName"]}} to {{$item(0).$node["Set"].json["clientName"]}}

I understand the workaround, but is this normal behavior?

It’s normal behavior. The HTTP node receives multiple items as input, and in the HTTP node, you are referencing a node that returns one item. n8n executes the node as many times as inputs and uses the input index to resolve the expressions. You get the following:

Iteration Expression Expression resolved
1 $node[“Set”].json[“clientName”] xxx
2 $node[“Set”].json[“clientName”] undefined
3 $node[“Set”].json[“clientName”] undefined
n $node[“Set”].json[“clientName”] undefined

Thanks for the answers; I didn’t come across this situation it seems :slight_smile:

Probably because you had not tried with multiple items, with only one item works fine. Anyways, great that it worked. Let us know if you have further questions.

or I was using SET within SplitInBatches along with the request in which case no problem occurs naturally.