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:

http://api.stackoverflow.com/0.8/questions/1429951&sort=votes

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

How can I do this?

share|improve this question
add comment

1 Answer

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.

http://api.stackoverflow.com/0.8/questions/1429951;2383701;619895?sort=votes&type=jsontext

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
add comment

You must log in to answer this question.

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