Expression Not Returning the Expected Value Inside

Hi everyone, I’m running into an issue with expressions in an HTTP Request node. I’m trying to pass a value from a previous node into the request body, but sometimes the value ends up empty or undefined, even though I can see the correct data in the execution preview.
My workflow is basically:
Webhook → Set → HTTP Request
In the Set node, I create a field called user_id, and then in the HTTP Request node I try to send that value in the JSON body.
Here’s roughly what I’m doing:// Set node
{
“user_id”: “{{$json.id}}”,
“email”: “{{$json.email}}”
}
// HTTP Request body
{
“id”: “{{$json.user_id}}”,
“email”: “{{$json.email}}”
}
// Sometimes the request ends up like this
{
“id”: “”,
“email”: “[email protected]
}
// I also tried referencing the node directly
{{$node[“Set”].json[“user_id”]}}

Describe the problem/error/question

The strange part is that the execution preview shows the correct value, but when the request is sent, user_id sometimes becomes empty.
I’m not sure if this is an expression scope issue or if I’m referencing the previous node incorrectly.
Has anyone experienced something similar with n8n expressions inside the HTTP Request node? I’m trying to figure out the most reliable way to pass values from one node to another.

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
2 Likes

Hi @Roseline This usually happens because of how n8n passes data between nodes. When you use $json, it only reads the current item coming into the node. If that item doesn’t contain user_id, the value will appear empty even if it existed in a previous node.

For example, if your HTTP Request node body looks like this:{
“id”: “{{$json.user_id}}”,
“email”: “{{$json.email}}”
}

it will only work if user_id and email are present in the current item. If another node modified the data structure or removed fields, $json.user_id may return an empty value.

A more reliable approach is to reference the node where the data was originally created. For example, if the values came from a Set node, you can reference it directly like this:{
“id”: “{{$node[‘Set’].json[‘user_id’]}}”,
“email”: “{{$node[‘Set’].json[‘email’]}}”
}

This tells n8n to always pull the values directly from the Set node, instead of relying on the current item.

Also check the Set node settings. If “Keep Only Set” is enabled, it removes other fields, which can sometimes cause expressions to return empty values later in the workflow.

So the main things to check are:
• Whether user_id exists in the current item
• Whether another node changed the data structure
• Or reference the specific node directly to avoid the issue.

2 Likes

Hi @Roseline i think instead of usng $json to call data you should call it with the named node like {{ $('Set').item.json.user_id }} so that it knows what to pick even if there is a mis match.

1 Like

Thanks for your reply @Niffzy @OMGItsDerek @Anshul_Namdev i got it solved

1 Like

@Roseline
I have experienced the same issue. Could you please assist me in resolving it? How did you manage to fix it?

the fix is using $('NodeName').item.json.fieldName to reference data from a specific previous node rather than just $json.fieldName. $json only reads whats flowing directly into the current node, so if a step upstream drops or renames a field the value’s gone. naming the source node explicitly makes it reliable no matter whats in between