1

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 to 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 to get answers or comments using a filter?

1 Answer 1

3

I think that 2 patterns can be thought for your solution. One is a method using custom filter. Another is a method using the endpoint for retrieving answers.

Pattern 1 :

You can create a custom filter for retrieving answers and answer's body using the endpoint of https://api.stackexchange.com/2.2/questions/### questionId ###.

  1. You can create the custom filters at http://api.stackexchange.com/docs/create-filter.
    • In your case, you can use this.
      • question.answers;answer.body;question.body was used as including filters.
      • The delimiter is ;.
    • As a result, you retrieve "filter": "!T*hPNRA69ofM1izkPP".
    • When you use the filter, please do URL encode it.
      • !T*hPNRA69ofM1izkPP becomes %21T%2ahPNRA69ofM1izkPP.
  2. You can retrieve answers and answer's body using the endpoint.
    • When the question ID of your question is used, it's https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=%21T%2ahPNRA69ofM1izkPP.

Result of pattern 1

When you can access to https://api.stackexchange.com/2.2/questions/6827752?&site=stackoverflow&filter=%21T%2ahPNRA69ofM1izkPP, you can get answers and answer's body.

Pattern 2 :

As the endpoint for retrieving answers, you can use /questions/{ids}/answers. If the question ID is 6827752 in your question, the endpoint is as follows. In this case, in order to retrieve answer's body, filter=withbody is used.

Result of pattern 2

If this was not useful for you, I'm sorry.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.