2

This is a follow up to a previous question of mine, and the starting point is that, given a list of reputation objects retrieved via /users/{ids}/reputation, I can easily retain only the entries with post_type == 'answers' and then get post_id for each of them, ending up with a list of answer_ids.

Given this list of answer_ids, how can I efficiently obtain the list of question objects associated to those answer_ids without losing the information of which question comes from which answer_id?

Clearly, I could make one /answers/{ids}/questions request for each of the answer_ids, but this means... I'm being kicked out with a 503 (Service unavailable) (hence the tag).

On the other hand, making one single /answers/{ids}/questions request for all the ids (well, I should actually make a request for chunks of 100 entries; then maybe I have to browse the few resulting pages; but this probably still means a small number of requests), I'm a bit unsure about whether those questions are obtained in the same order as the the answer_ids. Quite the opposite, from this answer I understand that there's no guarantee at all that that's the case.

If the retrieved questions are not sorted as the answer_ids, then the only way I see to re-establish the relation is to make a /answers/{ids} request as well (again, in chunks of 100 entries, ...), so that I can recognize which question corresponds to which answer_id, as the question_id is both in questions and answers.

But this looks a bit a convoluted approach. Plus, retrieving the whole answer objects when all I need is the question_id for each of them seems overkill.

Is there any other strategy I could adopt? Or is the latter one I described (retrieving all questions and all answers from the answer_ids) just fine?

1 Answer 1

1
+100

On the other hand, making one single /answers/{ids}/questions request for all the ids (well, I should actually make a request for chunks of 100 entries; then maybe I have to browse the few resulting pages; but this probably still means a small number of requests), I'm a bit unsure about whether those questions are obtained in the same order as the the answer_ids.

That's the way to go, but make sure you change the filter to one where answers is checked; it's off by default:

enter image description here

That will enable you to find match the questions with the answers you queried for.

Because I love self-referential examples, here is a call which finds the question for this very answer, and you can see the answer_id in the result:

enter image description here

1
  • Oh, so there is a way to get questions with all the answers in it, but not answers with their one question in it. Strange... Commented Dec 24, 2021 at 16:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.