# UN Comtrade International Trade Data Scraper (`compute-edge/un-comtrade-trade-scraper`) Actor

Extract UN Comtrade international trade statistics — imports/exports by reporter country, partner, HS commodity code, and year. Powered by the official UN Comtrade public preview API.

- **URL**: https://apify.com/compute-edge/un-comtrade-trade-scraper.md
- **Developed by:** [Compute Edge](https://apify.com/compute-edge) (community)
- **Categories:** Lead generation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 results

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/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
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.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use 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

## UN Comtrade International Trade Data Scraper

Extract official **UN Comtrade** international trade statistics straight from the United Nations public API. Perfect for **market research, supply-chain analysis, economic forecasting, and competitive intelligence** on global trade flows.

The UN Comtrade Database is the world's most comprehensive trade dataset, covering imports, exports, and re-exports between **200+ countries** going back to 1962. This Actor wraps the official public preview endpoint and pushes results directly into your Apify dataset — no API key required.

### What you get

| Field | Description |
| --- | --- |
| `period` | Reporting period (year or year-month) |
| `reporterDesc` | Country reporting the trade |
| `partnerDesc` | Trading partner country |
| `flowDesc` | Trade direction (Import, Export, Re-Export, etc.) |
| `cmdCode` | HS or SITC commodity code |
| `cmdDesc` | Commodity description |
| `primaryValue` | Trade value in USD |
| `netWgt` / `grossWgt` | Weights in kilograms |
| `qty` / `qtyUnit` | Reported quantity and unit |
| `motDesc` | Mode of transport |

### How to scrape UN Comtrade

1. Open the Actor's input form.
2. Set **Reporter Country Code** to the UN M49 code of the country whose trade you want — for example **842 (USA)**, **156 (China)**, **276 (Germany)**, **392 (Japan)**, **826 (UK)**.
3. Choose **Period** (year). Use commas to query multiple years.
4. Pick **Frequency** — Annual (`A`) or Monthly (`M`).
5. Pick **Trade Flow** — Goods (`C`) or Services (`S`).
6. Set **Commodity Code** to `TOTAL` for all goods or any 2/4/6-digit HS code (e.g. `87` for vehicles, `2709` for crude oil, `8517` for telephones).
7. Set **Partner Code** to `0` for World, or another M49 code for bilateral trade.
8. Click **Start** and watch the dataset fill in seconds.

### Use cases

- **Market entry analysis** — Quantify a country's import demand for your product category before launch.
- **Supply-chain risk** — Track concentration of imports/exports across partners.
- **Commodity research** — Build pricing or volume models from authoritative customs data.
- **Macro & ESG models** — Feed structured trade data into RAG pipelines or BI dashboards.

### Pricing

This Actor is priced at **$0.003 per result**. A typical query returns 100–5,000 records, so most runs cost a few cents in addition to Apify compute.

### Input example

```json
{
  "reporterCode": "842",
  "period": "2022",
  "frequency": "A",
  "tradeFlow": "C",
  "classification": "HS",
  "cmdCode": "TOTAL",
  "partnerCode": "0",
  "maxResults": 1000
}
````

### Output example

```json
{
  "period": "2022",
  "reporterDesc": "USA",
  "partnerDesc": "World",
  "flowDesc": "Export",
  "cmdCode": "TOTAL",
  "primaryValue": 2064787398567,
  "netWgt": null,
  "qty": null
}
```

### Related Actors

- **FRED Federal Reserve Economic Data Scraper** — pair trade volumes with macro indicators.
- **USAspending Government Spending Scraper** — for federal contracts touching imported inputs.
- **SEC EDGAR Filings Scraper** — public-company exposure to trade routes.

### FAQ

**Do I need an API key?** No. The Actor uses UN Comtrade's free public preview endpoint.

**Can I get monthly data?** Yes — set Frequency to `M` and Period to a `YYYYMM` value.

**Is the data official?** Yes — directly from the United Nations Statistics Division.

### Legal

This Actor accesses publicly available trade statistics published by the United Nations. Users are responsible for complying with the [UN Comtrade Terms of Use](https://comtradeplus.un.org/Help/Terms). The Actor does not bypass any authentication or rate-limit controls.

Support: bciccarelli6@gmail.com

# Actor input Schema

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

UN M49 country code of the reporting country. Examples: 842 (USA), 156 (China), 276 (Germany), 392 (Japan), 826 (UK), 156, 250 (France). Use 0 for World. Comma-separate for multiple.

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

Year(s) of data. Examples: '2022', '2023'. Comma-separate for multiple (e.g., '2021,2022,2023').

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

Annual (A) or Monthly (M) data.

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

Trade flow direction. C=Goods (default), S=Services. Use this to select dataset type.

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

Commodity classification scheme. HS = Harmonized System (most common).

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

HS commodity code. 'TOTAL' for all goods. Example: '01' (animals), '87' (vehicles). Comma-separate for multiple.

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

Partner country M49 code. 0 = World (default). Comma-separate for multiple.

## `maxResults` (type: `integer`):

Maximum total records to return across all queries. 0 = unlimited.

## Actor input object example

```json
{
  "reporterCode": "842",
  "period": "2022",
  "frequency": "A",
  "tradeFlow": "C",
  "classification": "HS",
  "cmdCode": "TOTAL",
  "partnerCode": "0",
  "maxResults": 1000
}
```

# Actor output Schema

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

No description

# 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("compute-edge/un-comtrade-trade-scraper").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("compute-edge/un-comtrade-trade-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).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 compute-edge/un-comtrade-trade-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=compute-edge/un-comtrade-trade-scraper",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "UN Comtrade International Trade Data Scraper",
        "description": "Extract UN Comtrade international trade statistics — imports/exports by reporter country, partner, HS commodity code, and year. Powered by the official UN Comtrade public preview API.",
        "version": "0.1",
        "x-build-id": "jbT8ZZYAEiPdfeSzH"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/compute-edge~un-comtrade-trade-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-compute-edge-un-comtrade-trade-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/compute-edge~un-comtrade-trade-scraper/runs": {
            "post": {
                "operationId": "runs-sync-compute-edge-un-comtrade-trade-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/compute-edge~un-comtrade-trade-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-compute-edge-un-comtrade-trade-scraper",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "reporterCode": {
                        "title": "Reporter Country Code (M49)",
                        "type": "string",
                        "description": "UN M49 country code of the reporting country. Examples: 842 (USA), 156 (China), 276 (Germany), 392 (Japan), 826 (UK), 156, 250 (France). Use 0 for World. Comma-separate for multiple.",
                        "default": "842"
                    },
                    "period": {
                        "title": "Period (Year)",
                        "type": "string",
                        "description": "Year(s) of data. Examples: '2022', '2023'. Comma-separate for multiple (e.g., '2021,2022,2023').",
                        "default": "2022"
                    },
                    "frequency": {
                        "title": "Frequency",
                        "enum": [
                            "A",
                            "M"
                        ],
                        "type": "string",
                        "description": "Annual (A) or Monthly (M) data.",
                        "default": "A"
                    },
                    "tradeFlow": {
                        "title": "Trade Flow",
                        "enum": [
                            "C",
                            "S"
                        ],
                        "type": "string",
                        "description": "Trade flow direction. C=Goods (default), S=Services. Use this to select dataset type.",
                        "default": "C"
                    },
                    "classification": {
                        "title": "Commodity Classification",
                        "enum": [
                            "HS",
                            "SITC"
                        ],
                        "type": "string",
                        "description": "Commodity classification scheme. HS = Harmonized System (most common).",
                        "default": "HS"
                    },
                    "cmdCode": {
                        "title": "Commodity Code",
                        "type": "string",
                        "description": "HS commodity code. 'TOTAL' for all goods. Example: '01' (animals), '87' (vehicles). Comma-separate for multiple.",
                        "default": "TOTAL"
                    },
                    "partnerCode": {
                        "title": "Partner Country Code",
                        "type": "string",
                        "description": "Partner country M49 code. 0 = World (default). Comma-separate for multiple.",
                        "default": "0"
                    },
                    "maxResults": {
                        "title": "Max Results",
                        "minimum": 0,
                        "maximum": 100000,
                        "type": "integer",
                        "description": "Maximum total records to return across all queries. 0 = unlimited.",
                        "default": 1000
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
