# Import & Export Trade Data — UN Comtrade (by Product & Country) (`noniner/trade-flows`) Actor

Official UN Comtrade trade data: value and quantity by reporter country, partner, product (HS code) and year, with country names resolved. Keyless via the public preview, or full data with a free Comtrade key. For sourcing, supply-chain and market research.

- **URL**: https://apify.com/noniner/trade-flows.md
- **Developed by:** [Fredrik Hansson](https://apify.com/noniner) (community)
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$100.00 / 1,000 trade query 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

## Import & Export Trade Data — UN Comtrade

Official **international trade data** from the UN Comtrade database: trade **value and quantity** by reporter country, partner country, product (HS code) and year — with country and product names resolved from Comtrade's reference tables.

Works **keyless** out of the box via Comtrade's public preview. Add a **free** Comtrade subscription key for full (non-sample) data and higher limits.

### What it's for

- **Sourcing & supply chain** — see which countries export a product, and how much.
- **Market research** — size a market by import/export value over time.
- **Competitive / trade intelligence** — who trades what, with whom.

### What you get

Per trade-flow row: reporter country, flow (import/export), partner country, HS commodity code (+ description when available), year, **trade value (USD)**, net weight and quantity.

### Input

| Field | Description |
|---|---|
| `reporters` | Reporter countries — ISO3 (`USA`, `DEU`), name (`Germany`) or numeric code. |
| `flow` | `import`, `export` or `both`. |
| `commodities` | HS codes (e.g. `8471` computers, `2709` crude oil). Empty = TOTAL (all goods). |
| `years` | Years to report. |
| `subscriptionKey` | Optional free Comtrade key for full data (leave empty for the public preview). |

#### Example

```json
{
  "reporters": ["USA", "Germany"],
  "flow": "import",
  "commodities": ["8471"],
  "years": ["2023"]
}
```

### Keyless vs full data

- **No key:** uses Comtrade's public *preview* endpoint — real data, but a capped sample. Great for trying it and for small pulls.
- **Free key:** get one at comtradeplus.un.org (free tier) and paste it into `subscriptionKey` for full, uncapped data.

### Pricing

Pay per use: one charge per query (reporter × flow × product × year), which can return many partner rows.

### Notes

- Data is sourced from UN Comtrade; figures reflect what reporting countries submit.
- Country names are resolved from Comtrade's public reference tables.

Built by the No Niner team.

# Actor input Schema

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

The countries whose trade to report — ISO3 code (e.g. USA, DEU), name (e.g. Germany) or numeric code. One per line.

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

Imports, exports or both.

## `commodities` (type: `array`):

HS commodity codes (e.g. 8471 computers, 2709 crude oil). Leave empty for TOTAL (all goods). One per line.

## `years` (type: `array`):

Years to report (e.g. 2023). One per line.

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

Optional free UN Comtrade subscription key for full (non-preview) data and higher limits. Leave empty to use the keyless public preview.

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

Max trade rows to return across all queries. One pay-per-event charge per query (reporter × flow × product × year) processed.

## `maxConcurrency` (type: `integer`):

Parallel queries. Keep low — Comtrade rate-limits the public preview.

## Actor input object example

```json
{
  "reporters": [
    "USA"
  ],
  "flow": "import",
  "commodities": [
    "8471"
  ],
  "years": [
    "2023"
  ],
  "maxResults": 2000,
  "maxConcurrency": 2
}
```

# Actor output Schema

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

All trade-flow rows in the default dataset.

# 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 = {
    "reporters": [
        "USA"
    ],
    "commodities": [
        "8471"
    ],
    "years": [
        "2023"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("noniner/trade-flows").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 = {
    "reporters": ["USA"],
    "commodities": ["8471"],
    "years": ["2023"],
}

# Run the Actor and wait for it to finish
run = client.actor("noniner/trade-flows").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 '{
  "reporters": [
    "USA"
  ],
  "commodities": [
    "8471"
  ],
  "years": [
    "2023"
  ]
}' |
apify call noniner/trade-flows --silent --output-dataset

```

## MCP server setup

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

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/mctL15mIMgbVrydmW/builds/MI9c3uBTEb2PVn1NM/openapi.json
