# Import Export Trade Data Scraper - UN Comtrade (`logiover/comtrade-trade-data-scraper`) Actor

Scrape global import & export trade statistics from UN Comtrade. Bilateral flows by country & HS commodity: value (USD), quantity & weight. Annual or monthly. No API key.

- **URL**: https://apify.com/logiover/comtrade-trade-data-scraper.md
- **Developed by:** [Logiover](https://apify.com/logiover) (community)
- **Categories:** Automation, Business
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, NaN bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.50 / 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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## Import Export Trade Data Scraper - UN Comtrade Statistics (No API Key)

Scrape global **import and export trade statistics** for any country pair straight from the official **UN Comtrade** database. This international trade data scraper returns clean **bilateral trade flows** broken down by country, HS commodity code, trade value (USD), quantity and net weight — annual or monthly, with no API key, no login and no registration.

Perfect for trade intelligence, market-entry research, supply-chain analysis, competitor sourcing and economics dashboards. Export to JSON, CSV, Excel or Google Sheets, or pull it through the Apify API.

> 🔎 **Keywords:** import export data scraper, UN Comtrade API, international trade data, trade statistics scraper, HS code trade data, bilateral trade flows, customs trade data, commodity trade scraper.

---

### What you get

One row per **reporter × partner × commodity × period × flow**:

- `reporter` / `reporterISO` — reporting country + ISO3 code
- `partner` / `partnerISO` — trading partner country + ISO3 code
- `flow` — Import or Export
- `period` — year (annual) or `YYYYMM` (monthly)
- `hsCode` / `commodity` — HS commodity code + description
- `tradeValueUsd` — trade value in USD
- `cifValueUsd` / `fobValueUsd` — CIF (imports) / FOB (exports) values
- `netWeightKg` — net weight in kg
- `qty` / `qtyUnit` — quantity & unit
- `scrapedAt` — ISO timestamp of the scrape

#### Sample output

```json
{
  "reporter": "USA",
  "reporterISO": "USA",
  "partner": "China",
  "partnerISO": "CHN",
  "flow": "Import",
  "period": "2023",
  "hsCode": "85",
  "commodity": "Electrical machinery and equipment",
  "tradeValueUsd": "127845300000",
  "cifValueUsd": "127845300000",
  "netWeightKg": "4120500000",
  "qtyUnit": "N/A",
  "scrapedAt": "2026-06-03T08:30:11.000Z"
}
````

***

### Use cases

- **Market-entry research** — see which countries buy a product and how much, before you enter a market.
- **Competitor & supplier sourcing** — find where a country imports a commodity from.
- **Commodity trade trends** — track import/export value over years or months.
- **Supply-chain & tariff impact analysis** — model how flows shift over time.
- **Economics & BI dashboards** — feed clean bilateral trade statistics into your reports.
- **AI agents & data products** — provide structured international trade data to LLM workflows.

***

### How to use

1. **Pick your countries** — one or more reporter countries and partner countries (plain names or M49 codes).
2. **Choose commodities, flow & period** — HS codes or an aggregation, import/export/both, and the years or months you want.
3. **Run & download** — export as JSON, CSV or Excel, or fetch via the Apify API. [Schedule](https://docs.apify.com/platform/schedules) it to refresh your trade datasets automatically.

#### Example — who do the USA & Germany import from China?

```json
{
  "reporters": "USA, Germany",
  "partners": "China",
  "flow": "import",
  "commodities": "AG2",
  "periods": "2022-2023",
  "frequency": "A"
}
```

#### Input fields

| Field | Description |
|---|---|
| `reporters` | Reporting country/countries — names, M49 codes, or `all`. Comma-separated. |
| `partners` | Trading partner(s) — names, codes, `World` (all combined), or `all`. |
| `flow` | `import`, `export`, or `both`. |
| `commodities` | Specific HS codes (`8703,8517`) or an aggregation: `TOTAL`, `AG2`, `AG4`, `AG6`. |
| `periods` | Year `2023`, list `2021,2022`, range `2020-2023`, or monthly `202301-202312`. Blank = last full year. |
| `frequency` | `A` (annual) or `M` (monthly). |
| `maxResults` | Maximum trade records to save. |
| `throttleMs` | Delay between API calls (keep ≥ 1100 for the keyless tier). |

***

### FAQ

#### Do I need a UN Comtrade API key?

No. This actor uses the keyless UN Comtrade preview tier — no registration, no key, no login.

#### Can I use plain country names?

Yes. Pass names like `Germany`, `China`, `USA` and the actor resolves them to the correct UN **M49** codes automatically.

#### What are AG2, AG4, AG6?

HS aggregation levels — `AG2` = all 2-digit HS chapters, `AG4` = 4-digit headings, `AG6` = 6-digit subheadings. You can also pass specific HS codes like `8703,8517`.

#### Is this company- or shipment-level data?

No — this is **statistical trade-flow data** (country × commodity × value), the official UN Comtrade figures. It is not shipment-level bill-of-lading or company records.

#### Can I export to Excel / Google Sheets?

Yes. Download as JSON, CSV, Excel, HTML or RSS, or use the Apify API and integrations (Make, Zapier, Google Sheets).

***

### Notes & best practices

- **Data source:** official **UN Comtrade** statistics (keyless preview tier).
- The keyless tier rate-limits to ~1 request/second and caps 500 records per query — the actor throttles and fans out across countries, commodities and periods automatically. Keep `throttleMs` ≥ 1100.
- For large jobs, split very broad queries (e.g. `all` reporters over many years) into smaller runs.

> ℹ️ This is an independent scraper of publicly available UN Comtrade statistics and is not affiliated with or endorsed by the United Nations.

### 📝 Changelog

#### 2026-06-05

- 🛡️ Reliability fix: results are no longer dropped by strict output validation — runs now complete cleanly even at high volume (thousands of results).
- ⚡ Stability & performance hardening; fresh rebuild.

#### 2026-06-04

- Verified live & refreshed build — reliability/maintenance pass.

# Actor input Schema

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

Reporting country/countries — names, M49 codes, or 'all'. Comma-separated. E.g. 'USA, Germany, China' or '842,276'.

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

Trading partner(s) — names, M49 codes, 'World' (all partners combined), or 'all'. Comma-separated.

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

Import, export, or both.

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

HS commodity codes (comma-separated, e.g. '8703,8517') OR an aggregation: 'TOTAL' (all), 'AG2' (all HS2 chapters), 'AG4', 'AG6'.

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

Years for annual (e.g. '2022,2023' or range '2020-2023') or months for monthly ('202301-202312'). Blank = last full year.

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

Annual or monthly data.

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

Maximum trade records to save.

## `throttleMs` (type: `integer`):

Delay between API calls. UN Comtrade keyless tier rate-limits ~1 req/sec — keep >= 1100.

## `proxyConfiguration` (type: `object`):

Apify proxy. Datacenter is fine.

## Actor input object example

```json
{
  "reporters": "USA",
  "partners": "World",
  "flow": "both",
  "commodities": "AG2",
  "periods": "",
  "frequency": "A",
  "maxResults": 1000,
  "throttleMs": 1100,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

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

Reporting country

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

Import / Export

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

Trading partner country

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

Year or YYYYMM

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

Harmonized System commodity

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

Commodity description

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

Trade value in USD

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

Net weight in kg

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

Quantity

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

Quantity unit

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

Reporter ISO3

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

Partner ISO3

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

CIF import value

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

FOB export value

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

ISO timestamp

# 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("logiover/comtrade-trade-data-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("logiover/comtrade-trade-data-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 logiover/comtrade-trade-data-scraper --silent --output-dataset

```

## MCP server setup

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

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Import Export Trade Data Scraper - UN Comtrade",
        "description": "Scrape global import & export trade statistics from UN Comtrade. Bilateral flows by country & HS commodity: value (USD), quantity & weight. Annual or monthly. No API key.",
        "version": "0.0",
        "x-build-id": "GcFxeV5C0IVb3bPVm"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/logiover~comtrade-trade-data-scraper/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-logiover-comtrade-trade-data-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/logiover~comtrade-trade-data-scraper/runs": {
            "post": {
                "operationId": "runs-sync-logiover-comtrade-trade-data-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/logiover~comtrade-trade-data-scraper/run-sync": {
            "post": {
                "operationId": "run-sync-logiover-comtrade-trade-data-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": {
                    "reporters": {
                        "title": "Reporter countries",
                        "type": "string",
                        "description": "Reporting country/countries — names, M49 codes, or 'all'. Comma-separated. E.g. 'USA, Germany, China' or '842,276'.",
                        "default": "USA"
                    },
                    "partners": {
                        "title": "Partner countries",
                        "type": "string",
                        "description": "Trading partner(s) — names, M49 codes, 'World' (all partners combined), or 'all'. Comma-separated.",
                        "default": "World"
                    },
                    "flow": {
                        "title": "Trade flow",
                        "enum": [
                            "both",
                            "import",
                            "export"
                        ],
                        "type": "string",
                        "description": "Import, export, or both.",
                        "default": "both"
                    },
                    "commodities": {
                        "title": "Commodities (HS codes)",
                        "type": "string",
                        "description": "HS commodity codes (comma-separated, e.g. '8703,8517') OR an aggregation: 'TOTAL' (all), 'AG2' (all HS2 chapters), 'AG4', 'AG6'.",
                        "default": "AG2"
                    },
                    "periods": {
                        "title": "Periods",
                        "type": "string",
                        "description": "Years for annual (e.g. '2022,2023' or range '2020-2023') or months for monthly ('202301-202312'). Blank = last full year.",
                        "default": ""
                    },
                    "frequency": {
                        "title": "Frequency",
                        "enum": [
                            "A",
                            "M"
                        ],
                        "type": "string",
                        "description": "Annual or monthly data.",
                        "default": "A"
                    },
                    "maxResults": {
                        "title": "Max results",
                        "minimum": 1,
                        "type": "integer",
                        "description": "Maximum trade records to save.",
                        "default": 1000
                    },
                    "throttleMs": {
                        "title": "Throttle (ms)",
                        "minimum": 600,
                        "type": "integer",
                        "description": "Delay between API calls. UN Comtrade keyless tier rate-limits ~1 req/sec — keep >= 1100.",
                        "default": 1100
                    },
                    "proxyConfiguration": {
                        "title": "Proxy configuration",
                        "type": "object",
                        "description": "Apify proxy. Datacenter is fine.",
                        "default": {
                            "useApifyProxy": true
                        }
                    }
                }
            },
            "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
