I want to retrieve top rated answer given the questions id. API documentiation states that one can get all answers matching "a set of ids" from a site using the answers/{ids}
method.
I have tried to the following URL: https://api.stackexchange.com/questions?site=stackoverflow.com&ids=32290879
which returns a set of items, but when I search through the page I don't find the matching question_id
(32209879
)
How do I retrieve the top rated answer given a question id?
You need to use the answers on questions (
/questions/{ids}/answers
) method, which returns answers for a set of question ids. You can then sort the answers by votes. However, the thing becomes more complicated if you pass more than 1 id. You'll then need to loop through every item and implement pagination.There are various SE API libraries for a variety of languages on StackApps. You can use one depending on your language.
Here's a JavaScript example:
And here's a Python one (using StackAPI):