3

I use https://api.stackexchange.com/docs. To get a sample question, I use the address https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow. Thanks to this, he gains a question. The following page shows https://api.stackexchange.com/docs/types/question that with the default filter the question will not have a body. I know I use a filter to get a body filter=withbody that is, the address comes out

https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=withbody

Now I would like to get answers for the question. That's why I want to use a filter filter=withanswers. This address

https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=withanswers

returns an error

{
  "error_id": 400,
  "error_message": "Invalid filter specified",
  "error_name": "bad_parameter"
}

How do get answers or comments using a filter?

5

You have to use a custom filter, the default provided filters are not going to cut it.

Here is an example for question id 4 on Stack Overflow

https://api.stackexchange.com/docs/questions-by-ids#order=desc&sort=activity&ids=4&filter=!-y(KwOdKR5Ga7mmruVArx2SJykc-M)3jKiDQBk1fq&site=stackoverflow&run=true

The filter value !-y(KwOdKR5Ga7mmruVArx2SJykc-M)3jKiDQBk1fq will return questions, answers and their comments.

See my answer on How to create API filters? to learn how to create filters in the UI.

You must log in to answer this question.

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