# Stack Overflow Answers

Returns one page of answers to a question: answer id, score, accepted flag, comment count, ISO 8601 dates, owner, HTML body, plain-text body and license. Sort by votes, activity or creation. A question without answers returns an empty list. Costs 1 credit per successful request.

- **Documentation:** [https://scrappa.co/docs/stackoverflow-api/stackoverflow_answers](https://scrappa.co/docs/stackoverflow-api/stackoverflow_answers)
- **API group:** Stack Overflow API
- **Endpoint:** `GET https://scrappa.co/api/stackoverflow/answers`

## Authentication

Send your Scrappa API key in the `X-API-KEY` request header. Paid endpoints also support accountless x402 payments when called without an API key.

## Parameters

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `question_id` | integer | Yes | Stack Overflow question id. |
| `sort` | string | No | votes, activity or creation. Defaults to votes. |
| `order` | string | No | asc or desc. Defaults to desc. |
| `page` | integer | No | 1-based page, 1-25. Defaults to 1. |
| `pagesize` | integer | No | Items per page, 1-100. Defaults to 30. |

## Example request

```bash
#!/bin/bash

curl -X GET \
    -H "x-api-key: YOUR_API_KEY_HERE" \
    "https://scrappa.co/api/stackoverflow/answers?question_id=11227809&sort=votes"
```

## Example response

```json
{
    "success": true,
    "data": {
        "question_id": 11227809,
        "answers": [
            {
                "answer_id": 11227902,
                "question_id": 11227809,
                "score": 35297,
                "is_accepted": true,
                "comment_count": 23,
                "created_at": "2012-06-27T13:56:42Z",
                "last_activity_at": "2024-03-04T17:37:13Z",
                "last_edited_at": "2024-03-04T17:37:13Z",
                "owner": {
                    "user_id": 922184,
                    "display_name": "Mysticial",
                    "reputation": 473513,
                    "user_type": "registered",
                    "link": "https://stackoverflow.com/users/922184/mysticial",
                    "profile_image": "https://i.sstatic.net/h7WDB.jpg?s=256"
                },
                "body": "<p><strong>You are a victim of <a href=\"https://en.wikipedia.org/wiki/Branch_predictor\" rel=\"noreferrer\">branch prediction</a> fail.</strong></p>\n<hr ...",
                "body_text": "You are a victim of branch prediction fail.\n\nWhat is Branch Prediction?\n\nConsider a railroad junction:\n\nImage by Mecanismo, via Wikimedia Commons. Use...",
                "license": "CC BY-SA 4.0"
            }
        ],
        "page": 1,
        "pagesize": 2,
        "has_more": true
    },
    "meta": {
        "endpoint_family": "answers",
        "billable": true
    }
}
```

## Errors

| Status | Error | Description |
| --- | --- | --- |
| 503 | Upstream Unavailable | The source could not be fetched after the attempt budget. Never charged. Safe to retry. |
| 500 | Parser Drift | The source returned a shape this parser does not recognise. The incident is reported. Never charged. |
| 422 | Invalid Parameter | A value in this request is invalid or the requested page is out of range. Never charged. |

## More Scrappa resources

- [API documentation](https://scrappa.co/docs)
- [Full LLM-readable API reference](https://scrappa.co/llms-full.txt)
- [OpenAPI specification](https://scrappa.co/docs/api.json)
- [Pricing](https://scrappa.co/pricing)
