Issue in API Pagination with Loops

Describe the problem/error/question

I am trying to paginate a HTTP API (swapi.dev) and it works for the 1st loop (Loop Over Items) where the names are displayed in console properly. Then on the 2nd “next” run, the Loop Over Items node simply passes the control to the If node without executing the loop. All subsequent next executions move straight to the if node without looping.

What is the error message (if any)?

No error messages.

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

I stop the workflow when I see that loop is not working.

Information on your n8n setup

  • n8n version: Latest
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (IDK so I guess Default):
  • Running n8n via (Docker):
  • Operating system: Ubuntu

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Removing since the workflow view is fixed!

Hi @sg_tech

Thanks for posting here and welcome to the community! :raised_hands:

When sharing your workflow’s JSON make sure to surround them with the backticks, like so:

```
// your json goes here
````

I formatted your initial post for better visibility :slight_smile:

In regards to your looping issue:

I was able to re-create your workflow and it looks fine to me, looping until there’s no tomorrow!
So I am wondering whether it could be due to memory restrictions on your end. Did you get any error messages, like below?

Hi,

Thanks for the tip and formatting my post.

The problem is that the Loop for Items only loops 1 time i.e. for the 1st list I receive from API. All the subsequent executions pass directly to the If block.

See the image:
1st API Response: The “Loop for Items” executes the loop printing the names in the console.
2nd and subsequent response: Passes directly to the If block without printing the names.

Hope the issue is clear now?

Thanks in advance…

SG

hello @sg_tech

That’s because you can’t use Loop over items node within the external “Loop” (linking back the Code1 node), as both the Loop node and that backlinking operate with the workflow’s $runIndex property, which then breaks the next Loop over items run.

In your case, you should move the Loop Over items node functionality to the sub-workflow, so your main workflow will be like this:

and sub-workflow (you actually don’t need a Loop node here, but you may use it as well):

The Aggregate node is needed to output only one item (another option - use No Operation Node with the option “Execute Once”

2 Likes

Tops!!! Changed into sub workflow and it works as expected. Will make the same changes in my original workflow later and hope it will work too :smiley:

Marked this as a solution…

Thanks a lot @barn4k!!!

1 Like

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