Not able to get array size from previous nodes

Describe the problem/error/question


I am trying to retrieve a data from a previous node but for some reason it does not work.

I tried to add a item list, but it throws me a error, but if I connect direct on the node that there is the information, it works fine.

The thing is:

I get a order data from a API, and after some validations I want to check how many products there are in my order. so I added a loop node, and for my batch size I added “{{ $(‘WooCommerce Trigger’).item.json.line_items }}” that has this information. but throws me an error.

do I have to make a variable? how can I retrieve this data correctly?

What is the error message (if any)?

[ERROR: Can’t get data for expression]

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

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

Hi @Marcello_Kera, I am very sorry you’re having trouble.

Before getting into your questions just a quick note to let you know that I have redacted secret and key values that appear to be hard-coded in your workflow. While these have now been redacted, you still want to rotate any keys and secrets posted on the internet as soon as you can.

As for the actual error, the basic expression should work provided your WooCommerce trigger node returns the correct data structure, but n8n might not be able to render a preview. Are you able to execute the workflow as a whole?

If you are looking to perform your action against every single of your line_items you might want to look at the Item Lists node instead. This node can split out an array field, and subsequent nodes would then perform their action for every single item they receive.

For example like so:

In this example, the HTTP Request node would run twice (once for each element in line_items), no need for a loop.

1 Like

Thanks for the reply, and also to remove the hardcoded things, I tried also to make it dynamic but didn’t worked out.

Maybe the way I tried to explain was not ok, my workflow works fine, retrieve data from woocomerce just fine, also goes to OMIE (the other system that I have to get data from), but the thing is, when I try to add data the to the “Item list” from the return or woocomerce or OMIE, I just can do that just if the “Item list” is right after the HTTP node, other wise It seems that further nodes are not able to use data from nodes that are 4 steps away.

Sorry if it’s a little confusing but also for me it’s ind hard.

When you say that I could do directly with the “item list” without a loop, in fact I can’t because for each item I have, I need to go to woocomerce get some extra data to insert on OMIE.

The flow is not totally finished, because I am constructing step by step since I am new on N8N.

I have already this implemented on a midlleware but I am trying to bring it everything here.

well, the thing is, I will keep trying to retrieve this data on other nodes. Because I can see it, but when I add to the fx it tells me that is not correct.

This sounds like you need the Merge node. This can combine items from two different branches. Here’s a quick example:

In this workflow, the HTTP Request would overwrite everything it receives from the previous node. The Merge request would then take the input from two different nodes and merges the first item from the HTTP Request node with the first item from the “Generate random data” node. Same for the second, third, etc. item.

If you have a different number of items returned by your nodes you might need to tweak the settings of the node a bit.

Is this what you had in mind?

Yes Thanks,

I really thought that since there was a node (independent of how far it was triggered from the actual node) I could use the data.

Now I am merging things to use, because I need to do a lot of data search to get the whole information before insert to the new system.

Thanks a lot

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.