# UN Comtrade International Trade Data Tracker (`gochujang/un-comtrade-trade-data`) Actor

Fetch bilateral trade data (exports/imports) from UN Comtrade's free Preview API. Query by reporter country, partner country, HS commodity code, and year. Ideal for tariff analysis, supply chain research, and geopolitical trade intelligence. No API key required.

- **URL**: https://apify.com/gochujang/un-comtrade-trade-data.md
- **Developed by:** [Hojun Lee](https://apify.com/gochujang) (community)
- **Categories:** Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 item processeds

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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## UN Comtrade International Trade Data Tracker

Fetch bilateral international trade data (exports and imports) from the **UN Comtrade Preview API** — completely free, no API key required. Query by reporter country, partner country, HS commodity code, and year range.

### What is UN Comtrade?

UN Comtrade is the world's largest repository of international merchandise trade statistics maintained by the United Nations Statistics Division. It contains annual, quarterly, and monthly trade flows reported by more than 200 countries and territories.

### Use Cases

- **Tariff & Trade Policy Analysis** — Track the impact of tariffs on bilateral trade flows (e.g., US-CN trade war, EU carbon border tax)
- **Supply Chain Intelligence** — Identify which countries export critical components (semiconductors, batteries, rare earths)
- **Geopolitical Research** — Monitor trade diversification, reshoring trends, and friend-shoring patterns
- **Commodity Market Research** — Track global trade volumes for specific HS codes (oil, LNG, steel, agricultural goods)
- **Academic & Financial Research** — Build datasets for macroeconomic models, country risk, or investment theses

### Supported Countries (ISO2)

| Code | Country       | Code | Country       |
|------|---------------|------|---------------|
| US   | United States | KR   | South Korea   |
| CN   | China         | IN   | India         |
| JP   | Japan         | GB   | United Kingdom|
| DE   | Germany       | FR   | France        |
| IT   | Italy         | CA   | Canada        |
| AU   | Australia     | BR   | Brazil        |
| MX   | Mexico        | RU   | Russia        |
| SA   | Saudi Arabia  |      |               |

Use `"0"` as the partner code to retrieve **world totals** (all partners combined).

### Input Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `reporters` | string\[] | `["US", "CN"]` | ISO2 codes of reporting countries |
| `partners` | string\[] | `["0"]` | ISO2 codes of partner countries, or `"0"` for world total |
| `commodityCodes` | string\[] | `["TOTAL"]` | HS commodity codes (e.g. `"8471"` for computers) or `"TOTAL"` |
| `flowCode` | string | `"X,M"` | Trade flow: `X` = exports, `M` = imports, `X,M` = both |
| `periods` | integer\[] | `[2023]` | List of years to query |
| `maxRecordsPerQuery` | integer | `250` | Max records per API call (max 250 for free tier) |

#### Common HS Commodity Codes

| Code | Description |
|------|-------------|
| `TOTAL` | All commodities |
| `8471` | Computers |
| `8517` | Phones & communication equipment |
| `8542` | Integrated circuits / semiconductors |
| `2709` | Crude oil |
| `2711` | Natural gas (LNG) |
| `7208` | Steel flat-rolled products |
| `2601` | Iron ore |
| `8703` | Passenger vehicles |

### Output Fields

Each record contains:

| Field | Description |
|-------|-------------|
| `reporter_code` | UN Comtrade numeric code of reporting country |
| `reporter_name` | Name of reporting country |
| `reporter_iso` | ISO3 code of reporting country |
| `partner_code` | UN Comtrade numeric code of partner country |
| `partner_name` | Name of partner country |
| `partner_iso` | ISO3 code of partner country |
| `flow` | Trade flow description (Export / Import) |
| `commodity_code` | HS commodity code |
| `commodity_description` | HS commodity description |
| `period` | Year of the data |
| `trade_value_usd` | Trade value in USD |
| `netweight_kg` | Net weight in kilograms |
| `qty` | Quantity (units vary by commodity) |
| `source` | Always `"UN Comtrade"` |

### Example Output

```json
{
  "reporter_code": 840,
  "reporter_name": "United States of America",
  "reporter_iso": "USA",
  "partner_code": 156,
  "partner_name": "China",
  "partner_iso": "CHN",
  "flow": "Import",
  "commodity_code": "8542",
  "commodity_description": "Electronic integrated circuits",
  "period": 2023,
  "trade_value_usd": 48234567890,
  "netweight_kg": 12345678,
  "qty": null,
  "source": "UN Comtrade"
}
```

### Pricing

This Actor uses **Pay-Per-Event (PPE)** pricing:

| Event | Price |
|-------|-------|
| Actor start | $0.005 |
| Per trade record fetched | $0.005 |

A typical run querying 2 countries × 1 partner × 1 commodity × 1 year returns up to 4 records, costing ~$0.025.

### API Limits

This Actor uses the **UN Comtrade Preview API** (free tier):

- Maximum 250 records per query
- Rate limited: ~1 request per second
- Annual data only (monthly/quarterly require a subscription)
- 15 supported reporter countries

For higher volume or more countries, the UN Comtrade API subscription ($500/year) unlocks full access.

### Data Attribution

Data sourced from [UN Comtrade](https://comtrade.un.org/) — United Nations Statistics Division. Please cite appropriately in academic or commercial publications.

***

### Related actors

- [World Bank Data Scraper](https://apify.com/gochujang/world-bank-data) — GDP, exports % of GDP, and trade balance to complement bilateral UN Comtrade flows
- [OECD Stats Tracker](https://apify.com/gochujang/oecd-stats-tracker) — OECD trade statistics for G7/G20 bilateral comparison alongside UN Comtrade
- [Eurostat Economic Data](https://apify.com/gochujang/eurostat-economic-data) — EU trade data for cross-border flows within the Eurozone to complement UN data

### Feedback

If this actor helps your trade research, a review helps others find it: [Leave a review on Apify Store](https://apify.com/gochujang/un-comtrade-trade-data#reviews)

***

**Keywords:** UN Comtrade, trade data, import export, international trade, trade balance, commodities, tariff, HS code, global trade, trade statistics, bilateral trade, country exports

# Actor input Schema

## `reporters` (type: `array`):

ISO2 country codes for reporting countries (e.g. US, CN, KR). Supported: US, CN, JP, DE, KR, IN, GB, FR, IT, CA, AU, BR, MX, RU, SA

## `partners` (type: `array`):

ISO2 country codes for partner countries, or '0' for world total

## `commodityCodes` (type: `array`):

HS commodity codes (e.g. 8471 for computers, 8517 for phones) or 'TOTAL' for all

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

X = Export, M = Import, X,M = Both

## `periods` (type: `array`):

List of years to query (e.g. 2022, 2023)

## `maxRecordsPerQuery` (type: `integer`):

Maximum records per API call (max 250 for free tier)

## Actor input object example

```json
{
  "reporters": [
    "US",
    "CN"
  ],
  "partners": [
    "0"
  ],
  "commodityCodes": [
    "TOTAL"
  ],
  "flowCode": "X,M",
  "periods": [
    2023
  ],
  "maxRecordsPerQuery": 250
}
```

# Actor output Schema

## `results` (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("gochujang/un-comtrade-trade-data").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("gochujang/un-comtrade-trade-data").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 gochujang/un-comtrade-trade-data --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,gochujang/un-comtrade-trade-data"
        }
    }
}
```

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/GeD3GXXS3YDrrXASs/builds/hvGP4ZnqkZnMZFMnq/openapi.json
