Set values lost after HTTP Request

Hi, i’m new to n8n, after playing around with it for a while I noticed the values that are being set using Set Node or Function node are lost after they go through a HTTP Request node.

How do I retain the values that are set before the HTTP Request is called for usage for some other purpose after the HTTP Request is called?

TIA!

Hey @need4eat,

Welcome to the community :sparkling_heart:

You can always refer to the values via the Variable Selector. So, instead of selecting the value from the Current Node, you can select the value from Nodes. Here’s a screenshot:

Here’s the example workflow (you can copy the below code and paste it in your Editor UI!):

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "message",
              "value": "Hello"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://webhook.site/09ec86c5-bf80-40f2-9d41-8b55ccb4ad6b",
        "options": {},
        "queryParametersUi": {
          "parameter": [
            {
              "name": "message",
              "value": "={{$json[\"message\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "Message from Previous Set node",
              "value": "={{$node[\"Set\"].json[\"message\"]}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hey Harshil, really appreciate the quick response :slight_smile:

Here’s what i’m trying

image

i’m setting the value like above in a function node…

and then after a couple of other HTTP request and set nodes,

i’m trying to access the above set attribute in a new function node like below

image

but this value is no longer available in items[0].json

Gotcha. In that case, you will have to reference the node. Instead of using items[0].json.customerType you will have to use $node['REFERENCE_NODE'].json.customerType.

That worked! Thank you @harshil1712 :smiley:

1 Like