Take the 2-minute tour ×
Stack Apps is a question and answer site for apps, scripts, and development with the Stack Exchange API. It's 100% free, no registration required.

If I retrieve a question like so:


I expect the answers to be sorted by votes, but they're not.

How can I do this?

share|improve this question

1 Answer 1

I believe the sort=votes parameter is for when you are retrieving multiple questions in one API call, such as with this URL - the questions in the response are ordered by vote.


In terms of how you could sort the responses - you do have the up + the down vote count from which you could sort on your application side, or you could make another request to the api with the extracted answer IDs and sort=votes, which is really a waste of resources when you already have all the data.

share|improve this answer
Hmmm... I never thought of sorting on the application side. I'll look into that. –  Nathan Osman May 29 '10 at 21:10
@George - OR you could take the questions/{id}/answers route and specify sort. sort on /questions/{id} applies to the question(s) returned. {id} is vectorized in both cases (in all cases, infact). –  Kevin Montrose May 30 '10 at 5:23
@Kevin: Oh, okay. I just thought it was wasteful to fetch the question and then all the answers. I guess it won't hurt if the first request has body=false set. –  Nathan Osman May 30 '10 at 5:45
@George - /questions/{id} only gives you the first "page" of answers anyway. If its the full set of answers (by answer_count) you should do the sort locally. Otherwise a second request is necessary anyway, might as well have the sorting done on our end. –  Kevin Montrose May 30 '10 at 6:24

You must log in to answer this question.

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