# API Pagination cursor loops - Ban events & Banned users

**URL:** <https://discuss.dev.twitch.com/t/api-pagination-cursor-loops-ban-events-banned-users/28912>\
**Category:** API\
**Created:** [November 4, 2020, 7:29pm UTC](https://discuss.dev.twitch.com/t/api-pagination-cursor-loops-ban-events-banned-users/28912 "2020-11-04T19:29:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Equinoxbig](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/equinoxbig/32/3162_2.png) [@Equinoxbig](https://discuss.dev.twitch.com/u/Equinoxbig)\
**Post date:** [November 4, 2020, 7:29pm UTC](https://discuss.dev.twitch.com/t/api-pagination-cursor-loops-ban-events-banned-users/28912/1 "2020-11-04T19:29:12Z")

</div>

Hello,

Using these endpoints :

- Ban events `GET https://api.twitch.tv/helix/moderation/banned/events`
- Banned users `GET https://api.twitch.tv/helix/moderation/banned`

I’m trying to get all the users banned on a channel, here is my code :

```auto
// nodeJS
const axios = require('axios');

function requestBans(cursor) {
    axios.get((cursor ? BASE_URL + `&after=${cursor}` : BASE_URL), {
            headers: {
                'Authorization': 'Bearer TOKEN',
                'Client-Id': 'CLIENT_ID'
            }
        })
        .then((res) => {
            if (res.data && res.data.data && res.data.pagination && res.data.pagination.cursor) {
                
                // Logging the users in the database

                setTimeout(() => {
                    requestBans(res.data.pagination.cursor);
                }, 3.5 * 1000);
            }

        })
        .catch((error) => {
            console.error(error.message)
        });
}

requestBans();

```

However at some point the cursor doesn’t update itself, it stays the same and the requests start looping (after about 500 users). I’m trying to get very old bans I’m not sure if that changes anything.

I’ve tried both endpoints multiple times sometimes the pagination doesn’t even work, I’ve seen a few topics about pagination looping but nothing helped me. The looping cursor : `eyJiIjp7Ik9mZnNldCI6MTIwfSwiYSI6eyJPZmZzZXQiOjE2MH19`

Also I know for a fact that there are more than 10k users currently banned on this channel using logs I’ve gathered over the last years using the moderation pubsub. But I’m trying to get older bans from before my pubsub log setup.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [November 4, 2020, 7:30pm UTC](https://discuss.dev.twitch.com/t/api-pagination-cursor-loops-ban-events-banned-users/28912/2 "2020-11-04T19:30:28Z")

</div>

> <https://github.com/twitchdev/issues/issues/18>
>
> \*\*Brief description\*\*
> 
> The API doesn't let me fetch ALL banned/timed out users… for a channel
> 
> \*\*How to reproduce\*\*
> 
> User this script with a valid broadcaster oAuth and the relevant broadcaster/user ID
> 
> \`\`\`
> const fs = require('fs');
> const path = require('path');
> 
> const got = require('got');
> 
> var users = {};
> 
> let page = 0;
> fetchPage = function(c) {
> got({
> url: 'https://api.twitch.tv/helix/moderation/banned',
> searchParams: {
> broadcaster\_id: 'ACasterID',
> after: c,
> first: 100
> },
> headers: {
> authorization: 'Bearer AnOauthForCaster'
> },
> responseType: 'json'
> })
> .then(resp =\> {
> page++;
> 
> for (var x=0;x\<resp.body.data.length;x++) {
> users\[resp.body.data\[x\].user\_id\] = 1;
> }
> 
> console.log('Page',page,'has',resp.body.data.length,'users',Object.keys(users).length);
> 
> fs.appendFileSync(path.join(
> \_\_dirname,
> 'pages',
> page + '.json'
> ), JSON.stringify(resp.body,null,4));
> if (resp.body.pagination && resp.body.pagination.cursor) {
> fetchPage(resp.body.pagination.cursor);
> }
> })
> .catch(err =\> {
> console.log(err);
> });
> }
> fetchPage('');
> \`\`\`
> 
> \`\`\`
> $ node fetch.js
> Page 1 has 100 users 100
> Page 2 has 100 users 200
> Page 3 has 100 users 200
> Page 4 has 100 users 200
> Page 5 has 100 users 200
> Page 6 has 100 users 200
> Page 7 has 100 users 200
> Page 8 has 100 users 200
> Page 9 has 100 users 200
> Page 10 has 100 users 200
> { HTTPError: Response code 500 (Internal Server Error)
> at EventEmitter.emitter.on (SOMEWHERE/node\_modules/got/dist/source/as-promise.js:109:31)
> at process.\_tickCallback (internal/process/next\_tick.js:68:7) code: undefined, name: 'HTTPError' }
> \`\`\`
> 
> Additionally page 2 thru 10 are identical
> 
> \*\*Expected behavior\*\*
> 
> Page 1 has 100 users 100
> Page 2 has 100 users 200
> Page 3 has 100 users 300
> Page 4 has 100 users 400
> 
> and so on till all banned users are fetched
> 
> \*\*Additional context or questions\*\*
> 
> Original Post: https://discuss.dev.twitch.tv/t/bug-moderation-api-for-banned-users-is-bugged/23483

---

<div class="post-metadata">

**Author:** ![Equinoxbig](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/equinoxbig/32/3162_2.png) [@Equinoxbig](https://discuss.dev.twitch.com/u/Equinoxbig)\
**Post date:** [November 4, 2020, 8:13pm UTC](https://discuss.dev.twitch.com/t/api-pagination-cursor-loops-ban-events-banned-users/28912/3 "2020-11-04T20:13:11Z")

</div>

Well thank you very much I guess, I thought it had been repaired since then, as some dev answered in the forum post linked to this issue. I guess this really puts [such statements](https://twitter.com/TwitchDev/status/903398416126009345?s=20) into perspective Jebaited

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [December 4, 2020, 8:13pm UTC](https://discuss.dev.twitch.com/t/api-pagination-cursor-loops-ban-events-banned-users/28912/4 "2020-12-04T20:13:15Z")

</div>

Closed on December 4, 2020, 8:13pm UTC

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