Hi everyone, I’m having an issue with expressions in n8n. I’m trying to access a value from a previous node, but instead of getting the value, I get:
[undefined]
My workflow is:
HTTP Request → Set → HTTP Request
In the second HTTP Request node, I’m trying to use:
{{$json.user.id}}
But the output is [undefined], even though I can see the data exists in the previous node.
Sometimes it works, sometimes it doesn’t, which is confusing.
I’m not sure if:
• The data structure is different than I think
• I should be referencing the previous node directly
• Or I’m accessing the wrong path
Describe the problem/error/question
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.)
Hi @Keira_Becky instead of json$.user.id try using {{ $input.first().json.user.id }} or {{ $('Your Node Name').first().json.user.id }} sometimes first().item.json or item.objectName occurs to be mindful with that, and it would work.
@Keira_Becky the intermittent part is the clue — your Set node is probably outputting multiple items and only some have user.id. drop a Code node between Set and the second HTTP Request to filter those out:
the Set node flattens user.id into userId so the second request doesn’t need nested access, and the Code node kills any items where it came back undefined before they hit the next HTTP call. swap the URLs for your real endpoints.