# Stack Overflow Search

Searches Stack Overflow questions. Each question carries id, title, link, tags, score, view count, answer and comment counts, accepted answer id, closed reason, bounty, ISO 8601 dates, owner with reputation and profile link, the HTML body, a plain-text body and the license. Pass q, tagged or both. Page N returns page N. Costs 1 credit per successful request.

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

## 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 |
| --- | --- | --- | --- |
| `q` | string | No | Search text. Required unless tagged is set. |
| `tagged` | string | No | Only questions with all these tags, comma or semicolon separated, e.g. php,laravel. |
| `sort` | string | No | activity, votes, creation or relevance. Defaults to relevance with q, otherwise activity. |
| `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/search?q=laravel+queue&tagged=php&sort=votes"
```

## Example response

```json
{
    "success": true,
    "data": {
        "search_parameters": {
            "q": "laravel queue",
            "tagged": "php",
            "sort": "votes",
            "order": "desc"
        },
        "questions": [
            {
                "question_id": 25877752,
                "title": "Laravel queue process timeout error",
                "link": "https://stackoverflow.com/questions/25877752/laravel-queue-process-timeout-error",
                "tags": [
                    "php"
                ],
                "score": 82,
                "view_count": 112267,
                "answer_count": 4,
                "comment_count": 5,
                "is_answered": true,
                "accepted_answer_id": 26238686,
                "created_at": "2014-09-16T20:21:27Z",
                "last_activity_at": "2022-12-24T01:39:22Z",
                "owner": {
                    "user_id": 1512641,
                    "display_name": "Will Durney",
                    "reputation": 1258,
                    "user_type": "registered",
                    "accept_rate": 86,
                    "link": "https://stackoverflow.com/users/1512641/will-durney",
                    "profile_image": "https://www.gravatar.com/avatar/76b63456d16d4c9877f9c590487fc755?s=256&d=identicon&r=PG"
                },
                "body": "<p>I'm on Laravel using <code>php artisan queue:listen</code> to run queued jobs. One of these jobs is fairly involved and takes a long time, and so I...",
                "body_text": "I'm on Laravel using php artisan queue:listen to run queued jobs. One of these jobs is fairly involved and takes a long time, and so I'm getting the f..."
            }
        ],
        "page": 1,
        "pagesize": 2,
        "has_more": true
    },
    "meta": {
        "endpoint_family": "search",
        "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)
