Search code examples
stackexchange-apistackexchange

Stack Exchange API


After get the answer with API, we get an object without a body.

{
  "items": [
    {
      "owner": {
        "reputation": 31,
        "user_id": 7256724,
        "user_type": "registered",
        "profile_image": "https://i.sstatic.net/pQ5II.jpg?s=128&g=1",
        "display_name": "Dzinot",
        "link": "https://stackoverflow.com/users/7256724/dzinot"
      },
      "is_accepted": false,
      "score": 2,
      "last_activity_date": 1494515438,
      "creation_date": 1494515438,
      "answer_id": 43919322,
      "question_id": 18987292
    }
  ],
  "has_more": false,
  "quota_max": 10000,
  "quota_remaining": 9401
}

How to receive the body of the answer?


Solution

  • You can retrieve the body by adding a query parameter of filter=withbody. For example, when /2.2/answers/43919322?order=desc&sort=activity&site=stackoverflow in URL of your question is used, the URL is as follows.

    https://api.stackexchange.com/2.2/answers/43919322?order=desc&sort=activity&site=stackoverflow&filter=withbody&access_token=#####&key=#####
    

    If you want to retrieve the data using curl, you can use this.

    curl "https://api.stackexchange.com/2.2/answers/43919322?order=desc&sort=activity&site=stackoverflow&filter=withbody&access_token=#####&key=#####" | gunzip
    

    Reference :

    If I misunderstand your question, I'm sorry.