Scenarios keeps looping although it should stop

Describe the issue/error/question

Hello, I have a scenario that @RicardoE105 was kind enought to help me put together with his reply to my question here: Loop through pagination in HTTP node

I have fixed the scenario however I want to only loop a custom API from page 1 to page 5 (There are some 3 thousand pages in the api) and save the data to a spreadsheet.

However, after this is acomplished, my HTTP Request node starts again to loop through the pages non stop. What am i doing wrong, now? :thinking:

Please share the workflow

here’s a video too.
https://drive.google.com/file/d/1R3vwDETq7fSHcoQd14vYVsbmi6dXIsun/view?usp=sharing

I’m running n8n on Vultr with docker

Thanks in advance for your advice!

Hey @th3liam ,
in your IF node you check if your fake-api response has the next url with ?page=5

Your first api request https://fake-api-pagination-m3j5j7bsccr1.runkit.sh/api returns:

{"count":24979,"next":"https://fake-api-pagination-m3j5j7bsccr1.runkit.sh/api?page=2","previous":null,"results":[{"cve_art":"09157948"}]}

But your second https://fake-api-pagination-m3j5j7bsccr1.runkit.sh/api?page=2 for ?page=2 does not return a next page url;

{"count":24979,"next":null,"previous":null,"results":[{"cve_art":"01234567"}]}

This resets your loop to the first page thus looping forever.

2 Likes

As @marcus mentioned. The API I shared with you only has two pages to simulate pagination. Since you change the condition in the IF, which checks if there is more data, you get an infinity loop. You should be able to do it with the API you want to work with instead of the demo API.

1 Like

Thank you for your comments fellas!

The pagination in the actual custom API has over 1,000 pages. I fixed the infinite loop by editing the values in the IF node to stop when the value in “next” is equal to 5. ( I only wanted to loop though 5 pages) and in the node options I enabled “Execute once”