# Get Streams - Inconsistent response using "first" parameter

**URL:** <https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053>\
**Category:** API\
**Created:** [April 19, 2020, 9:48am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053 "2020-04-19T09:48:06Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccarlsen](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@ccarlsen](https://discuss.dev.twitch.com/u/ccarlsen)\
**Post date:** [April 19, 2020, 9:48am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/1 "2020-04-19T09:48:06Z")

</div>

`GET https://api.twitch.tv/helix/streams?game_id=516575&first=100`

If I make the above request I’m getting a somewhat inconsistent response. Sometimes it returns 100, sometimes 99, 98 or even 97. Even though there’s 100+ results. Even if I set it to `&first=50` it will sometimes return 49 or 48 for example.

Is this normal behaviour? And is there a way to ensure I always get 100 results exactly?

---

<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:** [April 19, 2020, 10:13am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/2 "2020-04-19T10:13:56Z")

</div>

Did this recently start happening or has it always done this.

It may be related to

> [@Intermittent Error 400 (Invalid Cursor) from Helix Streams API](https://discuss.dev.twitch.com/t/intermittent-error-400-invalid-cursor-from-helix-streams-api/25035):
>
> Around 12:30 PST I began seeing errors with pagination on the Helix Streams endpoint. Here is the response: Body: {"error":"Bad Request","status":400,"message":"invalid cursor"} Here was the chain of pagination before hitting the error: https://api.twitch.tv/helix/streams?first=100&type=all https://api.twitch.tv/helix/streams?first=100&type=all&after=ZXlKeklqbzVOakl5Tmk0MU5Ua3hNemszT1RreU1pd2laQ0k2Wm1Gc2MyVXNJblFpT25SeWRXVjkgZXlKeklqbzFNek0zTGpRNE1qSTFOakEwTWprME5pd2laQ0k2Wm1Gc2MyVXNJblFpT25Se…

---

<div class="post-metadata">

**Author:** ![ccarlsen](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@ccarlsen](https://discuss.dev.twitch.com/u/ccarlsen)\
**Post date:** [April 19, 2020, 10:19am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/3 "2020-04-19T10:19:20Z")

</div>

I’ve been trying to get this to work for a couple of days now.

I want to get ALL the live streams for a specific game so I’m making a chain of requests and telling to stop if there’s less than 100. But with this issue it will just randomly stop, sometimes even on the first page. I don’t get it.

---

<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:** [April 19, 2020, 10:20am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/4 "2020-04-19T10:20:02Z")

</div>

Whats the actual request you are making?

---

<div class="post-metadata">

**Author:** ![ccarlsen](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@ccarlsen](https://discuss.dev.twitch.com/u/ccarlsen)\
**Post date:** [April 19, 2020, 10:41am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/5 "2020-04-19T10:41:01Z")

</div>

`https://api.twitch.tv/helix/streams?game_id=32982&first=100`  
If I make the above request right now it returns (randomly) either 98 or 99 results. Even though there’s more than 100 people streaming GTA V right now.

Weirdly If I do the exact same but for VALORANT it returns 100 pretty consistently  
`https://api.twitch.tv/helix/streams?game_id=516575&first=100`

Same issue for RDR2. There’s more than 100 streams but If I do this it returns 98/99  
`https://api.twitch.tv/helix/streams?game_id=493959&first=100`

---

<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:** [April 19, 2020, 10:42am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/6 "2020-04-19T10:42:44Z")

</div>

Seeing similar. Not sure if bug or something else.

Pagination with streams has a lot of fun issues.

best bet is to potentially paginate till you get no more cursor.

---

<div class="post-metadata">

**Author:** ![ccarlsen](https://avatars.discourse-cdn.com/v4/letter/c/b38774/32.png) [@ccarlsen](https://discuss.dev.twitch.com/u/ccarlsen)\
**Post date:** [April 19, 2020, 10:47am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/7 "2020-04-19T10:47:15Z")

</div>

I tried that. But then it will keep going forever because there’s always a cursor, even on the last page.

My only conclusion is that the first parameter is broken because anything you put, it might return somewhere between 1-4 less than that. I just changed it to `&first=80` and it returned 79.

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [April 19, 2020, 11:40am UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/8 "2020-04-19T11:40:30Z")

</div>

Stopping when the results is less than the `first` param is an unreliable way to paginate even if this was working perfectly.

The reason is, if the total number of streams is a multiple of your first param the final page would have a results equal to `first`, and because it still has a cursor (Get Streams endpoint has a cursor on the final page to allow for traversal of results in either direction) if you blindly attempt to use that cursor as the `after` value it’ll loop you back to the start and you’ll just endless loop.

To properly paginate the Get Streams endpoint you need to not assume that results \< `first` is the end, as there could still be more pages. You also need to retry any bad cursors, such as `IA`. And you need to detect looping, this can either be done through a check of the cursor length/decoding, or by comparing the results you’re getting to the results you’ve previously collected (if you jump from results with 1 or 0 viewers, to a page of streams with hundreds or thousands, you’re back at page 1)

---

<div class="post-metadata">

**Author:** ![Xopa](https://avatars.discourse-cdn.com/v4/letter/x/96bed5/32.png) [@Xopa](https://discuss.dev.twitch.com/u/Xopa)\
**Post date:** [April 19, 2020, 3:27pm UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/9 "2020-04-19T15:27:30Z")

</div>

I am also getting a different number of items on each page when using the `/clips` endpoint.

These requests return 61, 52, 45 results respectively, in spite of the `first=100` parameter.  
`https://api.twitch.tv/helix/clips?broadcaster_id=423486275&first=100&started_at=2020-02-28T18:24:27Z&ended_at=2020-02-29T14:24:27Z`  
`https://api.twitch.tv/helix/clips?broadcaster_id=423486275&first=100&started_at=2020-02-28T18:24:27Z&ended_at=2020-02-29T14:24:27Z&after=eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1UQXcifX0`  
`https://api.twitch.tv/helix/clips?broadcaster_id=423486275&first=100&started_at=2020-02-28T18:24:27Z&ended_at=2020-02-29T14:24:27Z&after=eyJiIjpudWxsLCJhIjp7IkN1cnNvciI6Ik1qQXoifX0`

Checking the `cursor` parameter instead of comparing `total` with `first` is certainly how it should be done, but the problem is we need to do more requests than expected.

---

<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:** [April 19, 2020, 3:50pm UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/10 "2020-04-19T15:50:06Z")

</div>

Clips is unrelated to streams

See also

> <https://github.com/twitchdev/issues/issues/80>
>
> \*\*Brief description\*\*
> 
> Larger date ranges omit clips from the response when us…ing Get Clips
> 
> https://dev.twitch.tv/docs/api/reference#get-clips
> 
> \*\*How to reproduce\*\*
> 
> https://dev.twitch.tv/docs/api/reference#get-clips
> 
> Calling 
> 
> \> https://api.twitch.tv/helix/clips?broadcaster\_id=66016174&started\_at=2020-03-01T12:00:00Z&ended\_at=2020-03-30T12:00:00Z&first=100
> 
> Fails to return the clip
> 
> \> https://api.twitch.tv/helix/clips?id=TrappedColdSashimiTBTacoLeft
> 
> But
> 
> \> https://api.twitch.tv/helix/clips?broadcaster\_id=66016174&started\_at=2020-03-04T00:00:00Z&ended\_at=2020-03-05T12:00:00Z&first=100
> 
> Returns it.
> 
> The second date range is inside the first so the clip in question should be returned in the first lookup. One assumes other clips maybe missing from "large" date range lookups.
> 
> \*\*Expected behavior\*\*
> 
> Return all clips created inside the date range
> 
> \*\*Additional context or questions\*\*
> 
> Report on discord starts here
> 
> https://discordapp.com/channels/504015559252377601/523675960797691915/689052568780931117

---

<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:** [May 19, 2020, 3:54pm UTC](https://discuss.dev.twitch.com/t/get-streams-inconsistent-response-using-first-parameter/25053/11 "2020-05-19T15:54:24Z")

</div>

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