8

When issuing requests to the stackoverflow-api, I set the pagesize to a 100 (which is the maximum possible). However, some json responses contain this attribute (normally at the very bottom):

"quota_remaining": 9954,
"quota_max": 10000,
"has_more": true

To give an example, such scenario comes to light when attempting to get the users on the stackoverflow forum (It goes without saying that the site has more than 100 users!)

How can I exploited this to get the subsequent results for my query?

This is the query URL: https://api.stackexchange.com/docs/users#pagesize=100&order=desc&sort=reputation&filter=default&site=stackoverflow&run=true

1 Answer 1

12

As long as has_more is set to true there is more data available. You can get this data by increasing the page parameter in your request subsequently and running new request with that changed page parameter.

The next url for your example would then be

https://api.stackexchange.com/docs/users#page=2&pagesize=100&order=desc&sort=reputation&filter=default&site=stackoverflow&run=true

The other both properties quota_remaining and quota_max refer to the maximum amount of queries you may issue on that day to the API. In your example case you have used 46 request on that day and may do another 9954.


WRT to the later comments

You can add filters to your request in order to have some more fields shown or left out in the response. In the adhoc query form you used, you can access these filters on the top right of the respective form.

Filter form

There just select edit and search for total in the section .wrapper. Afterwards click save. Afterwards it should show a filter id like !-q2Rj6nE, which is appended to your queries.

However as the FAQ states here, the total field is a rather expensive function and should be avoided to use on a regular basis, when you retrieve items anyway.

8
  • Hmm... I get your reasoning... so each page would return me 100 results (due to the pagesize attribute) right?
    – savagius
    Commented Mar 15, 2012 at 14:43
  • @savagius Exactly. So if there are 900 entries as a response to your query, you would have to do 9 queries total with the last having page=9 as a parameter.
    – Sirko
    Commented Mar 15, 2012 at 14:44
  • Got it! Though probably I'm gonna ask a lame question now, but how can I know how many entries there are...to the initial request I make? Cheers :)
    – savagius
    Commented Mar 15, 2012 at 14:46
  • @savagius There are two ways: Either just poll data until has_more is set to false or use a filter that includes the total property (to be found under .wrapper filters).
    – Sirko
    Commented Mar 15, 2012 at 14:52
  • I don't won't to sound annoying but could you elaborate on the second part (about the total property and wrapper filters)?
    – savagius
    Commented Mar 15, 2012 at 14:57
  • @savagius Have a look at my edit.
    – Sirko
    Commented Mar 15, 2012 at 15:05
  • 1
    Hi @Sirko, I've successfully managed keep polling for data, simply added a check on the has_more, and a page incrementer :).
    – savagius
    Commented Mar 15, 2012 at 16:07
  • Depending on how much polling you need to be doing, you may need to check the backoff property on the wrapper object, in case you need to insert a delay before querying too heavily.
    – danjah
    Commented Jun 28, 2016 at 5:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .