Erroneous behaviour in Webhook data

I am seeing this strange behaviour involving the data coming from the Webhook node.
image

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "const config = {\n  command: \"Read\",\n  params:{\n    object_key: \"object_key\",\n    record_id: $node[\"Webhook\"].json[\"query\"][\"id\"]\n  },\n  headers:{\n    app_id: \"app_id\",\n    api_key: \"api_key\"\n  },\n  data:\"\"\n};\nconst webhook = $node[\"Webhook\"].json[\"query\"][\"id\"];\n\nreturn [{json:{config,webhook}}];"
      },
      "name": "Config 1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        520,
        300
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "d1a08a23-c462-47b6-87ee-78d6cb6105b5",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        380,
        300
      ],
      "webhookId": "d1a08a23-c462-47b6-87ee-78d6cb6105b5"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Config 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

This is the output of the Function (Config) node:

As visible, the webhook and the config.params.record_id properties are both showing different data, whereas they are both referring to the same incoming data!

I’ve tried this with a Set node instead of the Function (Config) node, but same result, which makes me wonder that the issue might be with the Webhook node.

Also tried:

  • deleting and recreating the Webhook node
  • deleting and recreating the docker containers
  • refer to the incoming data as $json instead of $node["Webhook"].json
  • workflow setting for Save Execution Progress set to both false & true

Same result!

Hey @shrey-42!

I executed the workflow that you shared, and I can’t reproduce the issue. I get the same values for the record_id and the webhook fields. I tested both the GET and POST method.

I am running the latest version of n8n - 0.130.0

Hey @harshil1712, indeed I’ve observed the same as well.

The above scenario is occurring in my DO cloud docker instance. And when i tried to reproduce this in my local docker setup, everything works fine.

It would be helpful to know how to debug this for my cloud instance.

Can you share the whole workflow? I saw that you have another node after the config node in the picture you shared above. I tested it and was not able to replicate it

@RicardoE105

Workflow code
{
  "nodes": [
    {
      "parameters": {
        "functionCode": "const files = $json[\"body\"][\"field_338_raw\"].map(i => i.id);\n\nconst config = $node[\"Config\"].json;\nconfig.params.object_key = \"object_27\";\n\nconst res = files.map(f => {\n  let c = {...config};\n  c.params.record_id = f;\n  return {json:c};\n});\nreturn res;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1170,
        30
      ]
    },
    {
      "parameters": {
        "workflowId": "119"
      },
      "name": "Get Email",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        1020,
        30
      ]
    },
    {
      "parameters": {
        "functionCode": "const config = {\n  command: \"Read\",\n  params:{\n    object_key: \"object_28\",\n    record_id: $json[\"query\"][\"id\"]\n  },\n  headers:{\n    app_id: \"5e8d9d123d65a90015fb9bd8\",\n    api_key: \"4bfa5a80-797e-11ea-8f20-1723fb06065d\"\n  },\n  data:\"\"\n};\nconst webhook = $json[\"query\"][\"id\"];\n\nreturn [{json:{config,webhook}}];"
      },
      "name": "Config 1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        730,
        30
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{json:$json.config}];"
      },
      "name": "Config",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        870,
        30
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "d1a08a23-c462-47b6-87ee-78d6cb6105b5",
        "responseMode": "lastNode",
        "responseData": "allEntries",
        "options": {}
      },
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        560,
        30
      ],
      "webhookId": "d1a08a23-c462-47b6-87ee-78d6cb6105b5"
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1330,
        30
      ]
    }
  ],
  "connections": {
    "Function": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Email": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config 1": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config": {
      "main": [
        [
          {
            "node": "Get Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Config 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

So, after your message, i tried to add one node at a time and then execute again.
The problem seems to arise after the addition of the last Function node. Code:

const files = $json["body"]["field_338_raw"].map(i => i.id);

const config = $node["Config"].json;
config.params.object_key = "object_27";

const res = files.map(f => {
  let c = {...config};
  c.params.record_id = f;
  return {json:c};
});
return res;

Somehow, this code is influencing the values of the earlier function nodes.
As visible here, the values of config.params's properties (object_key, record_id) are getting replaced:


It’s not supposed to happen like this, right?

So, i have now been able to implement a workaround, using this code for the last Function node:

const files = $node["Get Email"].json["body"]["field_338_raw"].map(i => i.id);

const file_config = Object.assign({}, $node["Config"].json);

const res = files.map(f => {
  const c = {...file_config};
  c.params = {
      object_key: "object_27",
      record_id: f
  };
  return {json:c};
});
return res;

Although, i’m still not clear as to why c.params.object_key and c.params.record_id were acting like memory references for the config object from the Config 1 node.