Can't understand basic loop over items

Hello. I have a very simple workflow that got data from Google Places API and send this data to the code node “Extract displayNames only”:

[
  {
    "places": [
      {
        "displayName": {
          "text": "Joe's Pizza Broadway"
        }
      },
      {
        "displayName": {
          "text": "John's of Bleecker Street"
        }
      },
      {
        "displayName": {
          "text": "John's Pizzeria of Times Square"
        }
      }
    ],
    "nextPageToken": "xxxxxxx"
  }
]

The code node extract only the displayNames since I don’t need the parent “places” element:

[
  {
    "displayName": {
      "text": "Joe's Pizza Broadway"
    }
  },
  {
    "displayName": {
      "text": "John's of Bleecker Street"
    }
  },
  {
    "displayName": {
      "text": "John's Pizzeria of Times Square"
    }
  }
]

Then I have my Loop Over items node that is supposed to loop over the display names and append each display name to a google sheet. After all the rows for the current page had been added to the Google sheet there is a loop to execute again the Google Places request taking the nextPageToken as parameter to get the places for the next page from the API.

Everything is working except the loop over item only happens once so only the first page (3 display names) are appended to the Google Sheet. After this the “Loop Over displayNames” is always considered Done, so it does not go anymore through the Append row in sheet node. It is just looping over the main loop requesting the next pages.

Thank you for your help.

Unfortunately, this won’t work as expected.
In n8n, nodes process all incoming items at the same time.
So if the “done” output from the Loop returns 10 items, the next HTTP request node would run 10 times — and each of those would return the same 15 items again, leading to 10 × 15 duplicate results.

My suggestion is to clearly separate the loops:
First, fetch all items using the HTTP Request node (you can use its built-in pagination feature), and then process all items in a loop.

2 Likes

Thank you Franz. That’s very helpful. I actually noticed this HTTP Request node paging feature in the doc but I didn’t try it. My idea was to write the data in the Google sheet page by page so if for any reason something goes wrong at least I would have part of the data already stored. Plus If I fetch a lot of page that’s a lot of data piling up in memory and I have this workflow running locally on a Raspberry Pi. Anyway I guess I don’t have much choices, I tried many variations of my actual workflow and always got an issue somewhere.

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