# Thailand Open Data Studio — Gov Data Joins (`subimpact/th-open-data-studio`) Actor

Value layer on Thailand's official open data APIs (dev.data.go.th, provincial gdcatalog hosts, NSO): 6 join presets (GDP, Inflation, Labour, Tourism, Health, Demography) + custom joins + raw extraction, CSV/JSON/XLSX, AI-ready output, Open Data Common / CC attribution, BE years to CE.

- **URL**: https://apify.com/subimpact/th-open-data-studio.md
- **Developed by:** [subimpact](https://apify.com/subimpact) (community)
- **Categories:** AI, Automation, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $20.00 / 1,000 joined pulls

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#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

## Thailand Open Data Studio — Gov Data Joins 🇹🇭

Value layer on Thailand's official open data APIs. Join cross-dataset indicators into clean, AI-ready tables — or pull raw datasets by ID.

**Sources:** [dev.data.go.th](https://dev.data.go.th) catalogue (39,150+ datasets), provincial datastore hosts (`*.gdcatalog.go.th`), and the National Statistical Office API ([catalogapi.nso.go.th](https://catalogapi.nso.go.th)).

**Licence:** datasets are Open Data Common or Creative Commons Attributions as stated on each source record. Years are converted from Buddhist Era (พ.ศ.) to CE (subtract 543).

### Features

#### Studio mode (value layer) — $0.02/joined-pull

Six cross-dataset join presets, delivered as CSV / JSON / XLSX with an AI-ready package (JSON Schema + data dictionary + sample rows) and attribution sidecar:

- **T1 GDP & Economy by Year** — GDP, GDP per capita, population (national, current prices, million baht)
- **T2 Inflation & CPI by Year** — headline inflation rate × provincial CPI (all items)
- **T3 Labour Market by Year** — labour force participation × employment-to-population × unemployment (national)
- **T4 Tourism by Year (Nan)** — Thai/foreign/total tourists × visitors
- **T5 Health & Longevity by Year** — life expectancy (male/female) × death rate (NSO surveys)
- **T6 Demography & Migration by Year** — annual population (national) × population density × non-Thai citizens

Custom joins: bring your own dataset IDs (CKAN resource UUIDs or NSO table codes), key columns, join type (inner/left), aggregation (none/sum/mean), and API filters.

#### Extract mode (raw data pull) — $0.01/extract-pull

Pull 1-5 datasets raw by ID (CKAN resource UUID or NSO table code like `OS_02_0015_01`), no join, no reshape. Per-dataset files + manifest + attribution.

### Input

| Field | Type | Default | Notes |
|---|---|---|---|
| mode | select | studio | studio = value layer, extract = raw pull |
| preset | select | T1 | T1-T6 or custom |
| datasetIds | stringList | — | extract mode: 1-5 IDs |
| customDatasets | stringList | — | custom join: 2-6 IDs |
| customKey | stringList | \[year] | join keys ('year' auto-converts BE→CE) |
| customJoinType | select | inner | inner / left |
| customParams | textfield | — | JSON API filters |
| customAgg | select | none | none / sum / mean |
| format | select | json | json / csv / xlsx |
| webhookUrl | textfield | — | optional POST target |
| aiReady | checkbox | true | AI-ready package |
| includeAttribution | checkbox | true | attribution sidecar |

### Output

- **Dataset:** one summary record per run (mode, preset, rows, format, files, year range, run URL) — rendered as a table in the Output tab.
- **Key-value store:** the joined/extracted file, `*_verification.json`, `*_attribution.json`, `*_ai_ready.json` (studio) or per-dataset files + `extract_manifest.json` (extract).

### Example

```bash
## Studio: GDP & Economy preset, CSV
curl -X POST "https://api.apify.com/v2/acts/<ACTOR_ID>/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"preset":"T1","format":"csv"}'

## Extract: pull two NSO tables raw
curl -X POST "https://api.apify.com/v2/acts/<ACTOR_ID>/runs?token=$APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"mode":"extract","datasetIds":["OS_02_0015_01","OS_01_00014_01"],"format":"json"}'
```

### Notes

- All APIs are public and keyless (dev.data.go.th, provincial hosts, NSO).
- The dev catalogue is a development environment — endpoints may change. Provincial hosts are the more stable target.
- Data quality varies; some dev datasets are test data (e.g. Titanic). Presets use only verified production series.

# Actor input Schema

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

studio = value layer (presets, joins, AI-ready package). extract = raw data pull of 1-5 datasets by ID (cheaper per-pull event).

## `datasetIds` (type: `array`):

For mode=extract: list of Thai resource ids (CKAN UUIDs) or NSO table codes (OS\_/LFS\_/IMD\_/PHS\_/OLD\_ prefix) to pull raw (1-5). Leave empty to use studio mode.

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

Join bundle. T1 = GDP & Economy by Year. T2 = Inflation & CPI by Year. T3 = Labour Market by Year. T4 = Tourism by Year (Nan). T5 = Health & Longevity by Year. T6 = Demography & Migration by Year. custom = bring your own dataset ids.

## `customDatasets` (type: `array`):

For preset=custom: list of Thai resource ids (CKAN UUIDs) or NSO table codes to join (2-6). Leave empty to use a preset.

## `customKey` (type: `array`):

For preset=custom: key parts to join on. Use 'year' (auto-extracted from year/YEAR/ปี/TIME\_PERIOD fields, Buddhist Era converted to CE) or raw field names. All datasets must share these keys.

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

inner keeps only keys present in every dataset; left keeps all keys from the first dataset.

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

For preset=custom: JSON object of extra API params applied to every dataset, e.g. {"filters": {"AREA": "ทั่วราชอาณาจักร"}}.

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

none = keep raw rows (last value per key). sum = aggregate numeric values per key. mean = average numeric values per key.

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

File format delivered to the key-value store (dataset records are always JSON).

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

POST the result file to this URL after the run (3 retries with backoff). Leave empty to skip.

## `aiReady` (type: `boolean`):

Also emit JSON Schema + data dictionary + sample rows for LLM/RAG ingestion.

## `includeAttribution` (type: `boolean`):

Attach source/licence metadata sidecar to every output (Open Data Common / CC).

## Actor input object example

```json
{
  "mode": "studio",
  "preset": "T1",
  "customKey": [
    "year"
  ],
  "customJoinType": "inner",
  "customAgg": "none",
  "format": "json",
  "aiReady": true,
  "includeAttribution": true
}
```

# Actor output Schema

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

One summary record per run: mode, preset, row count, format, files, year range.

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

The joined dataset file (CSV/JSON/XLSX) in the default key-value store.

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

Raw dataset file(s) (CSV/JSON/XLSX) in the default key-value store.

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

JSON Schema + data dictionary + sample rows for LLM/RAG ingestion.

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

Source and licence metadata (Open Data Common / CC).

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("subimpact/th-open-data-studio").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("subimpact/th-open-data-studio").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 '{}' |
apify call subimpact/th-open-data-studio --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,subimpact/th-open-data-studio"
        }
    }
}

```

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/2a1IHil3sZUx7Ow9X/builds/eazTDr61OYCMr1kpE/openapi.json
