# Open Trivia Database Questions Scraper (`automation-lab/open-trivia-database-questions-export`) Actor

Export decoded Open Trivia Database questions with correct answers, distractors, filters, source status, and retrieval metadata for quiz and content workflows.

- **URL**: https://apify.com/automation-lab/open-trivia-database-questions-export.md
- **Developed by:** [Stas Persiianenko](https://apify.com/automation-lab) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $2.08 / 1,000 item extracteds

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Open Trivia Database Questions Scraper

Export decoded **open trivia database questions** for quizzes, games, education tools, and recurring content pipelines.

Choose an amount, category, difficulty, and question type. The Actor calls the official OpenTDB JSON API, decodes every question and answer, and writes integration-ready records to the default Apify dataset.

No OpenTDB account, API key, browser, or proxy is required.

### What does this Open Trivia Database questions scraper do?

The Actor turns an OpenTDB request into clean dataset rows.

It can:

- request 1–50 questions per run;
- filter by OpenTDB category ID;
- filter by easy, medium, or hard difficulty;
- choose multiple-choice or true/false questions;
- decode question text and answers safely;
- preserve correct answers and distractors separately;
- provide a combined answer array;
- optionally shuffle the combined answer array;
- attach source status and retrieval metadata;
- export as JSON, CSV, Excel, XML, or RSS through Apify.

### Who is it for?

#### Quiz and game developers

Populate a prototype, game round, or test environment without writing OpenTDB request and decoding code.

#### Educators

Create categorized question sets and then review or adapt them for a lesson.

#### Content teams

Schedule recurring exports for a question-bank ingestion workflow.

#### Data engineers

Receive stable camelCase fields and request provenance in the default dataset.

### Why use this Actor?

OpenTDB already exposes a public API. This Actor adds the operational layer needed in an Apify workflow:

- validated visual input;
- base64 decoding;
- normalized fields;
- structured retrieval metadata;
- dataset exports;
- schedules, webhooks, integrations, and API access;
- bounded retry handling for transient source failures;
- pay-per-result billing.

It intentionally stays close to the source rather than inventing unsupported enrichment.

### What data can you extract?

| Field | Description |
| --- | --- |
| `question` | Decoded question text |
| `correctAnswer` | Decoded correct answer |
| `incorrectAnswers` | Decoded distractor answers |
| `answers` | Correct answer and distractors, optionally shuffled |
| `category` | Category name returned by OpenTDB |
| `categoryId` | Requested category ID, or `null` without a category filter |
| `difficulty` | `easy`, `medium`, or `hard` |
| `type` | `multiple` or `boolean` |
| `sourceStatus` | Normalized source response status |
| `sourceResponseCode` | OpenTDB numeric response code |
| `sourceUrl` | Exact API URL used for retrieval |
| `retrievedAt` | UTC retrieval timestamp |
| `request` | Normalized amount and filters |

### How to get started

1. Open the Actor in Apify Console.
2. Set the number of questions from 1 to 50.
3. Optionally choose a category ID, difficulty, and type.
4. Choose whether the combined `answers` array should be shuffled.
5. Click **Start**.
6. Open the **Dataset** tab when the run finishes.
7. Download the data or connect it to another workflow.

A useful first run is:

```json
{
  "amount": 10,
  "category": 18,
  "difficulty": "medium",
  "type": "multiple",
  "shuffleAnswers": true
}
```

Category `18` is OpenTDB's Science: Computers category.

### Input parameters

| Input | Type | Default | Description |
| --- | --- | --- | --- |
| `amount` | integer | `10` | Questions requested; minimum 1, maximum 50 |
| `category` | integer | unset | Optional OpenTDB category ID from 9 to 32 |
| `difficulty` | string | unset | `easy`, `medium`, or `hard` |
| `type` | string | unset | `multiple` or `boolean` |
| `shuffleAnswers` | boolean | `false` | Randomize only the combined `answers` array |

Common category IDs include:

- `9` — General Knowledge
- `11` — Entertainment: Film
- `12` — Entertainment: Music
- `17` — Science & Nature
- `18` — Science: Computers
- `21` — Sports
- `22` — Geography
- `23` — History

OpenTDB controls its category taxonomy. Check the source documentation if a category changes.

### Output example

A dataset item follows this shape:

```json
{
  "question": "What does CPU stand for?",
  "correctAnswer": "Central Processing Unit",
  "incorrectAnswers": [
    "Central Process Utility",
    "Computer Personal Unit",
    "Central Processor Utility"
  ],
  "answers": [
    "Central Processing Unit",
    "Central Process Utility",
    "Computer Personal Unit",
    "Central Processor Utility"
  ],
  "category": "Science: Computers",
  "categoryId": 18,
  "difficulty": "medium",
  "type": "multiple",
  "sourceStatus": "success",
  "sourceResponseCode": 0,
  "sourceUrl": "https://opentdb.com/api.php?amount=10&encode=base64&category=18&difficulty=medium&type=multiple",
  "retrievedAt": "2026-01-15T12:00:00.000Z",
  "request": {
    "amount": 10,
    "category": 18,
    "difficulty": "medium",
    "type": "multiple"
  }
}
```

Actual question content varies because OpenTDB chooses the available records.

### How much does it cost to export OpenTDB questions?

This Actor uses pay-per-event pricing:

- one small Actor start charge per run;
- one `Question exported` charge for each saved dataset row.

You are not charged an item event for rejected, missing, or empty records.

The exact tier prices appear in Apify Console before you start a run. Larger subscription tiers receive lower per-question prices. Use the Console estimate as the current source of truth.

For example, a run returning 10 useful questions incurs one start event and 10 question events. A 50-question run incurs one start event and 50 question events.

### Recurring quiz-content workflow

Use an Apify schedule to refresh a focused question set:

1. Save a Task with category, difficulty, and type filters.
2. Set a weekly or monthly schedule.
3. Attach a webhook to the successful run event.
4. Read the default dataset from the webhook payload.
5. Deduplicate or review questions in your own question bank.

OpenTDB can return randomly selected questions. A schedule creates new snapshots; the Actor does not maintain history or compare runs itself.

### Export and integrations

The default dataset works with:

- JSON and JSONL ingestion;
- CSV and Excel downloads;
- Google Sheets integrations;
- Make and Zapier workflows;
- webhooks;
- Apify API clients;
- other Actors in a chained workflow.

Use `question`, `category`, `difficulty`, and `type` as common downstream mapping fields.

### Run with the Apify API

Replace `YOUR_TOKEN` with your Apify API token.

#### cURL

```bash
curl -X POST \
  "https://api.apify.com/v2/acts/automation-lab~open-trivia-database-questions-export/runs?token=YOUR_TOKEN&waitForFinish=120" \
  -H "Content-Type: application/json" \
  -d '{"amount":10,"category":18,"difficulty":"medium","type":"multiple"}'
```

#### JavaScript

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

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('automation-lab/open-trivia-database-questions-export').call({
  amount: 10,
  category: 18,
  difficulty: 'medium',
  type: 'multiple',
  shuffleAnswers: true,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);
```

#### Python

```python
from apify_client import ApifyClient

client = ApifyClient("YOUR_TOKEN")
run = client.actor("automation-lab/open-trivia-database-questions-export").call(
    run_input={
        "amount": 10,
        "category": 18,
        "difficulty": "medium",
        "type": "multiple",
    }
)
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(items)
```

### Use with MCP and AI assistants

Add the Apify MCP server to Claude Code:

```bash
claude mcp add --transport http apify \
  "https://mcp.apify.com?tools=automation-lab/open-trivia-database-questions-export"
```

#### Claude Desktop, Cursor, and VS Code setup

Use this MCP configuration in Claude Desktop, Cursor, or VS Code:

```json
{
  "mcpServers": {
    "apify": {
      "url": "https://mcp.apify.com?tools=automation-lab/open-trivia-database-questions-export"
    }
  }
}
```

Example prompts:

- "Get 15 easy general knowledge OpenTDB questions and return the answers as a table."
- "Export 20 hard science and nature multiple-choice questions for my review workflow."
- "Run my saved OpenTDB question Task and summarize category counts in its dataset."

Always verify generated educational or factual content before publishing it.

### Reliability and failure behavior

The Actor validates inputs before contacting the source.

Transient network errors, HTTP 429 responses, and server errors receive bounded retries. Deterministic input errors are not retried blindly.

A source response with no matching questions completes successfully with an empty dataset. Other OpenTDB response errors fail the run with a readable status.

The Actor does not use a proxy or browser. This keeps runtime and transfer usage small.

### Legality and responsible use

- OpenTDB allows at most 50 questions in one API request.
- Availability depends on the selected filter combination.
- Question selection and wording are controlled by OpenTDB.
- Random source selection can return repeated content across separate runs.
- Shuffling affects only the `answers` array.
- The separate `correctAnswer` and `incorrectAnswers` fields remain authoritative.
- This Actor does not verify each trivia fact.
- This Actor does not detect changes between historical runs.

Follow OpenTDB's terms and attribution guidance. Review content for accuracy, age suitability, bias, and licensing requirements before distribution.

### Troubleshooting

#### Why did my run return fewer or zero questions?

The chosen category, difficulty, and type combination may not contain enough available questions. Try removing one filter or requesting fewer questions.

#### Why is `categoryId` null?

You did not set a category filter. OpenTDB still returns a category name for each question, but no single category ID was part of the request.

#### Why does the answer order change?

`shuffleAnswers: true` deliberately randomizes the combined `answers` array on every run. Use the separate answer fields when checking correctness.

#### Why did the run fail with a source status?

OpenTDB reported an error other than a valid no-results response. Confirm the input and retry later if the source was rate limited or temporarily unavailable.

### FAQ

#### Does it need an OpenTDB token?

No. The Actor uses the anonymous official endpoint.

#### Can it download more than 50 questions per run?

No. The Actor follows the source's 50-question request limit rather than hiding multiple rate-limited calls behind one run.

#### Are HTML entities left in the output?

No. The Actor requests base64-encoded values and decodes them into normal Unicode text.

#### Can I export true/false questions?

Yes. Set `type` to `boolean`.

#### Can I schedule it?

Yes. Save the input as an Apify Task and attach an Apify schedule.

#### Does it remove duplicates across runs?

No. Store stable historical results in your own dataset or database and apply your preferred deduplication rule.

### Related automation-lab Actors

For other structured public-data pipelines, explore Actors published by [automation-lab](https://apify.com/automation-lab). Choose a related Actor only when its source and output fit your downstream workflow.

### Support

If the Actor fails with valid input, include the run ID and non-sensitive input in an Apify issue. Do not include API tokens or private downstream data.

# Actor input Schema

## `amount` (type: `integer`):

Number of questions requested from OpenTDB. The source API supports 1 to 50 questions per run.

## `category` (type: `integer`):

Optional OpenTDB category ID from 9 to 32. For example, 9 is General Knowledge, 17 is Science & Nature, and 18 is Computers.

## `difficulty` (type: `string`):

Optional difficulty filter. Leave unset to include all available difficulties.

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

Optional filter for four-choice multiple-choice questions or true/false questions.

## `shuffleAnswers` (type: `boolean`):

Randomize the combined answers array. Correct and incorrect answer fields remain separate and unchanged.

## Actor input object example

```json
{
  "amount": 10,
  "category": 18,
  "difficulty": "medium",
  "type": "multiple",
  "shuffleAnswers": false
}
```

# Actor output Schema

## `overview` (type: `string`):

Default dataset containing decoded questions, answers, filters, source status, and retrieval metadata.

# 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 = {
    "amount": 10,
    "category": 18,
    "difficulty": "medium",
    "type": "multiple",
    "shuffleAnswers": false
};

// Run the Actor and wait for it to finish
const run = await client.actor("automation-lab/open-trivia-database-questions-export").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 = {
    "amount": 10,
    "category": 18,
    "difficulty": "medium",
    "type": "multiple",
    "shuffleAnswers": False,
}

# Run the Actor and wait for it to finish
run = client.actor("automation-lab/open-trivia-database-questions-export").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 '{
  "amount": 10,
  "category": 18,
  "difficulty": "medium",
  "type": "multiple",
  "shuffleAnswers": false
}' |
apify call automation-lab/open-trivia-database-questions-export --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,automation-lab/open-trivia-database-questions-export"
        }
    }
}

```

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/YHsVzgqxfCKLX8Cfc/builds/lhBPUcVmnsIVa2qmY/openapi.json
