# Stack Overflow questions + answers search (Stack Exchange API) (`retrainmap/stackoverflow-questions`) Actor

Search Stack Overflow (or any Stack Exchange site) by query, tags, sort and date range through the public Stack Exchange API and get one row per question - title, tags, score, views, answers, owner, link, body text - plus its top answers as rows. CC BY-SA content; each row carries the license.

- **URL**: https://apify.com/retrainmap/stackoverflow-questions.md
- **Developed by:** [RetrainMap Team](https://apify.com/retrainmap) (community)
- **Categories:**
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $5.00 / 1,000 records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Stack Overflow questions + answers search — Stack Exchange API 2.3

One row per Stack Overflow question matched by your query, tags, sort and date range —
question id, title, tags, score, view count, answer count, answered / accepted-answer
flags, creation and last-activity dates, owner display name and reputation, canonical
link and the body as plain text — followed by the question's top answers as rows of
`row_type = answer`. Works for any Stack Exchange site (`site` input). Read through the
public Stack Exchange API 2.3 (https://api.stackexchange.com/docs), no login.

\*\*The default input (query `asyncio`, tag `python`, last activity first, 100 questions

- up to 3 answers each) succeeds within 5 minutes and returns rows\*\* — Apify auto-tests
  it daily.

### Data source, license and status

| | |
|---|---|
| Publisher | Stack Exchange, Inc. (Stack Overflow and the Stack Exchange network) |
| API | https://api.stackexchange.com/2.3 — public, documented at https://api.stackexchange.com/docs; `/search/advanced` for questions, `/questions/{ids}/answers` for answers, both with `filter=withbody` |
| Quota | **300 requests per day per IP without a key.** Your own app key (`stackexchange_key`, registered free at https://stackapps.com/apps/oauth/register) raises it to 10,000. Each 100 questions cost one request; answers cost about one request per 30 questions |
| Rate | At most one request per second by default; the API's `backoff` field is honoured; throttle errors (`error_id 502`) are retried after 30 s |
| **License / attribution** | **User contributions on Stack Exchange sites are licensed under Creative Commons Attribution-ShareAlike (CC BY-SA, version per post: https://stackoverflow.com/help/licensing).** Every row carries the API's own `content_license` as `license`, the author as `owner_display_name` and the canonical `link`. If you republish the text you must attribute the author, link to the post, and share alike |
| API terms | https://stackoverflow.com/legal/api-terms-of-use — this Actor identifies itself, respects the quota and backoff, and caches nothing |
| Known caveats | `body_text` is the HTML body with tags stripped and cut at 3,000 characters (code blocks lose their formatting); `view_count`, `answer_count`, `is_answered` are null on answer rows; `accepted_answer_id` is absent when nothing was accepted; deleted or closed questions are whatever the API returns |

Honesty note: the rows are the API's own fields renamed and flattened — nothing is
inferred, summarised or classified by this Actor, and a run stops with an error rather
than guess when the API's shape changes.

Identification: the requests carry a product-token User-Agent and the operator's
contact address in the standard `From:` header (RFC 9110 §10.1.2).

### Input

| Field | Type | Meaning |
|---|---|---|
| `query` | string | Free-text query (`q`); optional when tags are given |
| `tags` | array | Up to 5 tags, all must match (`tagged=a;b`) |
| `sort` | `activity` / `votes` / `creation` | Default `activity`, always descending |
| `from_date` / `to_date` | `YYYY-MM-DD` | Optional creation-date bounds (UTC, inclusive) |
| `include_answers` | boolean | Default true — top answers (by votes) as extra rows |
| `answers_per_question` | integer | Default 3, at most 20 |
| `max_records` | integer | Maximum **question** rows; default 100, at most 5,000 |
| `site` | string | Default `stackoverflow`; any site from https://api.stackexchange.com/docs/sites |
| `stackexchange_key` | secret string | Optional app key, raises the daily quota |
| `request_interval_ms` | integer | Default 1000 (floor 250) |
| `contact_email` | string | Sent in the `From:` header |

Example — highest-voted pandas questions about `groupby` created in 2026, no answers:

```json
{ "query": "groupby", "tags": ["python", "pandas"], "sort": "votes", "from_date": "2026-01-01", "include_answers": false, "max_records": 50 }
```

### Output (dataset row)

`row_type` (question / answer), `question_id`, `answer_id`, `site`, `title`, `tags`, `score`,
`view_count`, `answer_count`, `is_answered`, `accepted_answer_id`, `is_accepted`,
`creation_date`, `last_activity_date` (ISO 8601 UTC), `owner_display_name`,
`owner_reputation`, `owner_user_id`, `link`, `body_text` (≤ 3,000 chars), `license`,
`fetched_at`, `source`.

Answer rows repeat the parent question's `title`, `tags` and `accepted_answer_id` so each
row stands alone; their `link` is the question link with `#answer_id`.

A run summary (filters, row counts, requests, remaining daily quota, whether more pages
were available or the pay-per-event budget stopped the run) is stored as `RUN_SUMMARY`
in the run's key-value store.

### Pricing (pay per event)

| Event | Price |
|---|---|
| `run-start` — once per run | $0.10 |
| `record` — per row written (question or answer) | $0.005 |

The default pull (100 questions + up to 300 answers) costs at most $2.10; 100 questions
without answers cost $0.60. Rows stop when your run's maximum charge is reached; the run
summary says so.

### Operator

Steelyard Ventures LLC (RetrainMap) — info@steelyardclinical.com. Not affiliated with
Stack Exchange, Inc. The Actor writes only to its own dataset and key-value store; the
optional API key is sent only to api.stackexchange.com and never stored.

# Actor input Schema

## `query` (type: `string`):

Free-text query (the API's q parameter; matched against title and body). Optional when tags are given.

## `tags` (type: `array`):

Up to 5 tag names, e.g. python, pandas, c#. A question must carry every listed tag.

## `sort` (type: `string`):

activity = most recently active first (default), votes = highest score first, creation = newest first.

## `from_date` (type: `string`):

Optional lower bound on the question's creation date (UTC).

## `to_date` (type: `string`):

Optional inclusive upper bound on the question's creation date (UTC).

## `include_answers` (type: `boolean`):

Also write the top answers of each question as rows (row\_type = answer, sorted by votes).

## `answers_per_question` (type: `integer`):

Cap on answer rows per question when include\_answers is on (1-20).

## `max_records` (type: `integer`):

Stop after this many question rows. Answer rows come on top (at most answers\_per\_question each). Each 100 questions cost one API request plus a few for answers; the keyless quota is 300 requests per day.

## `site` (type: `string`):

API site parameter: stackoverflow (default), superuser, serverfault, askubuntu, math, or any other from https://api.stackexchange.com/docs/sites.

## `stackexchange_key` (type: `string`):

Your own app key from https://stackapps.com/apps/oauth/register raises the daily quota from 300 to 10,000 requests. Stored as a secret; sent only to api.stackexchange.com.

## `request_interval_ms` (type: `integer`):

Politeness delay towards api.stackexchange.com (floor 250 ms). The API's own backoff field is honoured on top.

## `contact_email` (type: `string`):

Sent in the standard From: request header so the data owner can reach the operator (RFC 9110 s10.1.2).

## Actor input object example

```json
{
  "query": "asyncio",
  "tags": [
    "python"
  ],
  "sort": "activity",
  "include_answers": true,
  "answers_per_question": 3,
  "max_records": 100,
  "site": "stackoverflow",
  "request_interval_ms": 1000,
  "contact_email": "info@steelyardclinical.com"
}
```

# Actor output Schema

## `results` (type: `string`):

One row per matched question followed by its top answers: ids, title, tags, score, views, dates, owner, link, body text, license.

## `results_csv` (type: `string`):

The same rows as a CSV file.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "query": "asyncio",
    "tags": [
        "python"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("retrainmap/stackoverflow-questions").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "query": "asyncio",
    "tags": ["python"],
}

# Run the Actor and wait for it to finish
run = client.actor("retrainmap/stackoverflow-questions").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "query": "asyncio",
  "tags": [
    "python"
  ]
}' |
apify call retrainmap/stackoverflow-questions --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,retrainmap/stackoverflow-questions"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/sDxxn1mxbpNjNjD9n/builds/yGaPCkbF1p79vEeVC/openapi.json
