# Pagination to loop all pages

**URL:** <https://community.n8n.io/t/pagination-to-loop-all-pages/27423>\
**Category:** Questions\
**Tags:** node, looping, external-api\
**Created:** [June 23, 2023, 6:40pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423 "2023-06-23T18:40:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesar\_dev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/cesar_dev/32/26592_2.png) [@cesar\_dev](https://community.n8n.io/u/cesar_dev)\
**Post date:** [June 23, 2023, 6:40pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/1 "2023-06-23T18:40:52Z")

</div>

## Describe the problem/error/question

I’m new to N8N. I need to loop all pages from this API.  
[https://bling.com.br/Api/v2/produtos/page=1/json/](https://bling.com.br/Api/v2/produtos/page=1/json/)

 ![image](https://europe1.discourse-cdn.com/n8n/original/3X/2/7/27d163983d856e03566268f491359b3b4ee17b57.png)

After to run HTTP, I split in items and run all others nodes. I made this manually to change every page because I don’t know how to do that.

## What is the error message (if any)?

## Please share your workflow

## Share the output returned by the last node

## Information on your n8n setup

- **n8n version:**
- **Database (default: SQLite):**
- **n8n EXECUTIONS\_PROCESS setting (default: own, main):**
- **Running n8n via (Docker, npm, n8n cloud, desktop app):**
- **Operating system:**

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 26, 2023, 3:20pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/2 "2023-06-26T15:20:28Z")

</div>

Hi @cesar_dev, happy to help with this one. Can you confirm how exactly your API behaves? I see it accepts a `page` parameter to query a specific page, but does it provide any information on the total number of pages in the response? Or any information on whether a next page exists or not?

---

<div class="post-metadata">

**Author:** ![cesar\_dev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/cesar_dev/32/26592_2.png) [@cesar\_dev](https://community.n8n.io/u/cesar_dev)\
**Post date:** [June 27, 2023, 11:43am UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/4 "2023-06-27T11:43:43Z")

</div>

Hello MutedJam,  
There is no information about the number of pages. I think when there is no number, it’s the end of pages.

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 27, 2023, 12:57pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/5 "2023-06-27T12:57:23Z")

</div>

Hi @cesar_dev, so if all you want to do is increment the number of pages until you hit an error you could make use of the `$runIndex` [variable](https://docs.n8n.io/code-examples/methods-variables-reference/#n8n-metadata) provided by n8n. Like so:

This might need some tweaking depending on how exactly your API works, but this basic template should help with that.

---

<div class="post-metadata">

**Author:** ![cesar\_dev](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/cesar_dev/32/26592_2.png) [@cesar\_dev](https://community.n8n.io/u/cesar_dev)\
**Post date:** [June 27, 2023, 1:22pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/6 "2023-06-27T13:22:22Z")

</div>

Hello,

Thanks for clarify. It works.  
Best regards,

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [June 27, 2023, 1:22pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/7 "2023-06-27T13:22:41Z")

</div>

Glad to hear, thanks so much for confirming 🙂

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/system/32/195824_2.png) [@system](https://community.n8n.io/u/system)\
**Post date:** [July 4, 2023, 1:23pm UTC](https://community.n8n.io/t/pagination-to-loop-all-pages/27423/8 "2023-07-04T13:23:12Z")

</div>

Closed on July 4, 2023, 1:23pm UTC

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