# Search limit parameter returning random number of objects

**URL:** <https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322>\
**Category:** API\
**Created:** [September 13, 2015, 1:28pm UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322 "2015-09-13T13:28:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adoyle2014](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/adoyle2014/32/783_2.png) [@Adoyle2014](https://discuss.dev.twitch.com/u/Adoyle2014)\
**Post date:** [September 13, 2015, 1:28pm UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322/1 "2015-09-13T13:28:08Z")

</div>

In initial call to search/channels endpoint i get 8 objects when i have set limit = 9. Then when using the \_next and \_prev links for pagination i get seemingly random amounts of objects returned while the offset holds steady at 9.  
Here is my call. Any reason for this behavior? What can be done to fix it if possible?  
Thanks.

```auto
var params = {'q': searchTerm, 'limit': 9};
var url = "https://api.twitch.tv/kraken/search/" + searchType + "?";

$.ajax({
                url: url,
                data: params,
                success: function(response) {
                    next = response._links.next;
                    prev = response._links.prev;
                    console.log(response);
                    callback(response);
                },
                error: ...

```

Here it is in action [https://github.com/Adoyle2014/FCC-TwitchAPIApp/tree/gh-pages](https://github.com/Adoyle2014/FCC-TwitchAPIApp/tree/gh-pages)

---

<div class="post-metadata">

**Author:** ![varinderdhesi](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/varinderdhesi/32/2873_2.png) [@varinderdhesi](https://discuss.dev.twitch.com/u/varinderdhesi)\
**Post date:** [September 15, 2015, 11:17am UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322/2 "2015-09-15T11:17:05Z")

</div>

Correct me if I’m wrong but you are saying when you first make a call to the API, you get 8 objects but then after going next/previous u have 9 objects?

---

<div class="post-metadata">

**Author:** ![ryanjlee](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@ryanjlee](https://discuss.dev.twitch.com/u/ryanjlee)\
**Post date:** [September 15, 2015, 8:02pm UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322/3 "2015-09-15T20:02:03Z")

</div>

I was getting the same kind of results using the search/streams endpoint. I did some testing and I believe what is happening is that when streams are ending, what would’ve been that 9th object is removed but the rest of the objects in the array in the server are still in place until the server reorders them. The same goes for the \_total property in the response. One possible solution is to increase the limit, store the objects, and use your own pagination functionality instead of making a request for each new page. But this comes at the cost of accuracy of what streams are actually still live.

---

<div class="post-metadata">

**Author:** ![Adoyle2014](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/adoyle2014/32/783_2.png) [@Adoyle2014](https://discuss.dev.twitch.com/u/Adoyle2014)\
**Post date:** [September 15, 2015, 9:47pm UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322/4 "2015-09-15T21:47:59Z")

</div>

the first part is right but the next doesn’t always give 9 objects either. The offset=9 in the url but sometimes it only gives 8 and even 7 when there are of course thousands to go through.

---

<div class="post-metadata">

**Author:** ![Adoyle2014](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/adoyle2014/32/783_2.png) [@Adoyle2014](https://discuss.dev.twitch.com/u/Adoyle2014)\
**Post date:** [September 15, 2015, 9:50pm UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322/5 "2015-09-15T21:50:55Z")

</div>

this makes sense for the streams but i am using the channels endpoint. They shouldn’t change, correct.  
The local pagination might end up being the workaround. Thanks

---

<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:** [October 15, 2015, 9:51pm UTC](https://discuss.dev.twitch.com/t/search-limit-parameter-returning-random-number-of-objects/3322/6 "2015-10-15T21:51:05Z")

</div>

Closed on October 15, 2015, 9:51pm UTC

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