Understanding how to loop data from a HTTP request output

I have tried using Split in Batches as well as Items lists node but can’t seem to figure it out. For example, an HTTP request outputs the following data:

[
  {
    "orders": [
      {
        "id": 1000,
        "name": "foo",
        "line_items": [
          {
            "name": "Cat",
            "price": 99
          }
        ]
      },
      {
        "id": 1001,
        "name": "bar",
        "line_items": [
          {
            "name": "Dog",
            "price": 99
          }
        ]
      },
      {
        "id": 1002,
        "name": "qux",
        "line_items": [
          {
            "name": "Cow",
            "price": 99
          }
        ]
      }
    ]
  }
]

I am trying to split all these orders into each order so that I can check with an IF node whether the line_items[0].name is what I’m looking for.

Split in batches returns only one item. The exact same array with one object (as that is the original item is). Items lists could only separate orders[0].line_items but what about orders[i] i.e. the complete orders.length number of items in that array?

I feel this should not be very difficult, but I’m hitting the wall using Code node as I can’t seem to figure out how to reference the items from the previous node.

Information on your n8n setup

  • n8n version: 0.214.2
  • Database you’re using (default: SQLite): postgres
  • Running n8n with the execution process [own(default), main]: not sure
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: docker

Hi Ibrahim,

In your case the way to go is using the Items lists and split out the orders, then you can plug directly a IF that will be evaluted for each order.

Here is an example:

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