# nextCursor

**URL:** <https://community.n8n.io/t/nextcursor/28289>\
**Category:** Questions\
**Tags:** http-request, pagination\
**Created:** [July 19, 2023, 5:37am UTC](https://community.n8n.io/t/nextcursor/28289 "2023-07-19T05:37:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![unicornParty](https://avatars.discourse-cdn.com/v4/letter/u/35a633/32.png) [@unicornParty](https://community.n8n.io/u/unicornParty)\
**Post date:** [July 19, 2023, 5:37am UTC](https://community.n8n.io/t/nextcursor/28289/1 "2023-07-19T05:37:17Z")

</div>

# Paginate / Loop with nextCursor. Am I supposed to “count” and offset, when they’re providing a “next” variable?

## In the response header, I get the count and the limit, but I don’t understand how to loop.

```auto
[
    {
        "body": {
            "list": {
                "meta": {
                    "totalCount": 426,
                    "limit": 100,
                    "nextCursor": "?limit=100&hasMoreElements=true&soIndex=426&poIndex=100&partnerId=10001078279&sellerId=101058904&createdStartDate=2023-07-12T05:03:59.721Z&createdEndDate=2023-07-19T05:03:59.721Z&shipNodeType=SellerFulfilled"
                },
                "elements": {
                    "order": [
                        {
                            "purchaseOrderId": "108820170097219",                
                    ...
                        ]

```

- **n8n Version0.234.1:**
- **Database (default: POSTGRES):**
- **Running n8n via: Caprover :**

---

<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:** [July 19, 2023, 3:15pm UTC](https://community.n8n.io/t/nextcursor/28289/4 "2023-07-19T15:15:14Z")

</div>

Hi @unicornParty, it looks like your API provides all information required to query additional pages in the `body.list.meta.nextCursor` field.

You should be able to do something like this:

This workflow appends the `body.list.meta.nextCursor` field when present, otherwise it uses an empty string instead. I don’t have access to the Walmart API, but perhaps you can give this a go with your own credentials?

I’ve also removed what seems to be a token from the workflow you have shared, to be safe you might want to rotate/recreate the secrets you have used in this workflow.

---

<div class="post-metadata">

**Author:** ![unicornParty](https://avatars.discourse-cdn.com/v4/letter/u/35a633/32.png) [@unicornParty](https://community.n8n.io/u/unicornParty)\
**Post date:** [July 19, 2023, 10:54pm UTC](https://community.n8n.io/t/nextcursor/28289/5 "2023-07-19T22:54:22Z")

</div>

thank you so much for responding.

In your example, how will the next request be queried?  
I “SET” the _nextCursor_ “IF” next _is not empty._

I already SET the base URL, so I was trying to combine SET URL and SET NEXT to loop…

---

<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:** [July 20, 2023, 10:27am UTC](https://community.n8n.io/t/nextcursor/28289/6 "2023-07-20T10:27:28Z")

</div>

> In your example, how will the next request be queried?

Hi @unicornParty, the example HTTP Request uses a URL expression of `https://marketplace.walmartapis.com{{ $json?.body?.list?.meta?.nextCursor ? $json.body.list.meta.nextCursor : "" }}`

The snippet inside the curly braces `$json?.body?.list?.meta?.nextCursor ? $json.body.list.meta.nextCursor : ""` uses the [ternary operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_operator). So on the first execution (when there is no `json.body.list.meta.nextCursor` field) the request would simply go to `https://marketplace.walmartapis.com`, but when the field is populated it would be attached to this URL.

I couldn’t test this myself so just used this as a dummy URL, but now revisiting your original workflow you probably want to use an expression like this instead as I’ve missed the `/v3/orders` part before:

```auto
https://marketplace.walmartapis.com/v3/orders{{ $json?.body?.list?.meta?.nextCursor ? $json.body.list.meta.nextCursor : "" }}

```

---

<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:** [October 18, 2023, 10:28am UTC](https://community.n8n.io/t/nextcursor/28289/7 "2023-10-18T10:28:21Z")

</div>

Closed on October 18, 2023, 10:28am UTC

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