# UN Comtrade Trade Data Scraper - Bilateral Trade by HS Code (`thirdwatch/trade-data-scraper`) Actor

Scrape bilateral trade data from UN Comtrade. Get import/export values between any two countries at HS code level. Find top traded product categories, track trade trends over time. Covers 200+ countries, all HS codes.

- **URL**: https://apify.com/thirdwatch/trade-data-scraper.md
- **Developed by:** [Thirdwatch](https://apify.com/thirdwatch) (community)
- **Categories:** E-commerce, Automation, Lead generation
- **Stats:** 18 total users, 4 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.90 / 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/actors/running/actors-in-store.md#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

## UN Comtrade Trade Data Scraper

> **Thirdwatch portfolio:** 5K users across 88 public Actors, 2M+ records delivered, and >99% run success. [Explore all Thirdwatch Actors](https://apify.com/thirdwatch).

> Source verified India trade buyers and suppliers from official UN Comtrade data: HS codes, bilateral trade volumes, country-pair flows — for B2B trade & sourcing teams.

### Find verified India importers and exporters

Bilateral trade flows from UN Comtrade — the official source behind every paid trade-intelligence product on the market. Filter by reporter country, partner, HS code, and year to find which countries India imports from and exports to in your category, and at what volumes. The starting point for any India-focused trade or sourcing pipeline.

### HS code trade data for B2B sourcing

Drill from 2-digit HS chapters down to 4-digit headings and 6-digit subheadings to find exactly the product flows you care about. Pair with [IndiaMart](https://apify.com/thirdwatch/indiamart-supplier-scraper?fpr=9m2cd6) and GST verification to go from "India imports $4.2B of HS 8517 from China" to a vetted supplier shortlist.

### Free alternative to Panjiva and ImportGenius

Panjiva, ImportGenius, Volza, and Export Genius all charge $5K-$50K/year — and most license the same UN Comtrade dataset upstream. This actor goes straight to the official source at ~$0.001/record with no contract, no seat licensing, and machine-readable JSON out of the box.

### What you get

Structured bilateral trade records from the UN Comtrade database — the world's most comprehensive international trade dataset. Query import or export flows between any two of 200+ countries, at any HS code level (2-digit chapter, 4-digit heading, or 6-digit subheading), across annual or monthly periods. Every record includes trade value in USD, net weight, quantity, and a human-readable commodity description.

### Output fields

| Field | Description |
|-------|-------------|
| `reporter_country` | Reporting country |
| `partner_country` | Partner country |
| `flow` | `import` or `export` |
| `hs_code` | HS commodity code |
| `hs_description` | Product description |
| `trade_value_usd` | Trade value in USD |
| `cif_value_usd` | CIF value in USD (imports) |
| `fob_value_usd` | FOB value in USD (exports) |
| `net_weight_kg` | Net weight in kg |
| `quantity` | Quantity traded |
| `quantity_unit` | Unit of quantity (kg, units, etc.) |
| `unit_price_usd` | Derived unit price (trade value / quantity) |
| `year` | Reference year |
| `period` | Reference period (YYYY or YYYYMM) |

### Example output

```json
{
    "reporter_country": "India",
    "partner_country": "China",
    "flow": "import",
    "hs_code": "8517",
    "hs_description": "Telephone sets and other apparatus for transmission of voice, images or data",
    "trade_value_usd": 4200000000,
    "cif_value_usd": 4200000000,
    "net_weight_kg": 85000000,
    "quantity": 85000000,
    "quantity_unit": "kg",
    "unit_price_usd": 49.41,
    "year": 2023,
    "period": "2023"
}
```

### Input parameters

| Parameter | Required | Description |
|-----------|----------|-------------|
| `reporterCountry` | No | The reporting country. One of `India`, `China`, `USA`, `UK`, `Germany`, `Japan`, `South Korea`, `France`, `Italy`, `Canada`, `Australia`, `Brazil`, `Mexico`, `Indonesia`, `Thailand`, `Vietnam`, `Malaysia`, `Singapore`, `UAE`, `Saudi Arabia`. Default `India`. |
| `partnerCountry` | No | The trade partner country. Same list as `reporterCountry`. Default `China`. |
| `hsCode` | No | HS code filter. Use 2-digit chapter (e.g., `85` for electronics), 4-digit heading (e.g., `8517` for telecom equipment), or 6-digit subheading. Leave empty for all chapters. |
| `flow` | No | `imports` (goods into reporter from partner) or `exports` (goods out of reporter to partner). Default `imports`. |
| `years` | No | Single year (`"2023"`) or comma-separated years for trends (`"2020,2021,2022,2023"`). Default `"2023"`. |
| `frequency` | No | `annual` for yearly totals or `monthly` for per-month breakdowns. Default `annual`. |
| `maxResults` | No | Maximum records to return, sorted by trade value descending (top categories first). Default `25`. |

### Use cases

- **B2B exporters finding India buyers by HS code**: Identify which countries India imports your category from and at what volume — then build a country-pair targeting plan.
- **Sourcing teams finding verified Indian suppliers**: Use trade flows to find established export categories, then drill down via IndiaMart + GST verification.
- **Trade financing / fintech screening trade flows**: Underwrite invoices and trade-credit lines using bilateral volumes as base-rate context.
- **Government / policy researchers**: Analyze trade imbalances, tariff impacts, and commodity concentration with the official dataset.
- **Trade analysts**: Track bilateral trade flows and year-over-year trends across commodity categories.
- **Economists**: Research international trade patterns and commodity dependence.
- **Business strategists**: Identify export opportunities and import substitution targets.
- **Supply chain teams**: Benchmark bilateral volumes for sourcing decisions.

### Use cases & recipes

Step-by-step guides on [thirdwatch.dev/blog](https://thirdwatch.dev/blog):

- [Build a Supply Chain Risk Dashboard from Trade Flows (2026)](https://thirdwatch.dev/blog/build-supply-chain-risk-dashboard-from-trade-flows)
- [Find Emerging Import-Export Categories with UN Comtrade (2026)](https://thirdwatch.dev/blog/find-emerging-import-export-categories-with-trade-data)
- [Research Tariff Impact with Bilateral Trade Data (2026)](https://thirdwatch.dev/blog/research-tariff-impact-with-bilateral-trade-data)
- [Track India-China Trade Flows with UN Comtrade Data (2026)](https://thirdwatch.dev/blog/track-india-china-trade-flows-with-un-comtrade)

### Pricing

Pay-per-result pricing. Tiered discounts apply automatically based on usage volume.

| Tier | Price per result |
|------|------------------|
| FREE | $0.0015 |
| BRONZE | $0.00125 |
| SILVER | $0.001 |
| GOLD | $0.00085 |

### Limitations

- UN Comtrade data typically lags 1-2 years — the most recent complete year of annual data is usually published 12-18 months after year-end.
- Some country-commodity pairs report sparsely or not at all, depending on the reporter's customs coverage.
- HS code granularity varies by reporter — not every country reports at the 6-digit level.
- Monthly data is not available for every reporter; annual coverage is broader.
- The enumerated country list covers the top 20 reporters. For other countries, pass a numeric M49 code directly.

### Compared to alternatives

- **vs. UN Comtrade web portal**: This actor returns machine-readable JSON you can pipe into dashboards, models, and pipelines. No manual CSV export per query.
- **vs. Panjiva ($25K+/yr), ImportGenius, Volza, Export Genius**: All license UN Comtrade upstream and resell it with a UI markup. Thirdwatch uses the same official source — free upstream, ~$0.001/record, no enterprise contract, no per-seat fees.
- **vs. Apify Store alternatives**: No other maintained UN Comtrade scraper on the Apify Store — this is the only production-grade option.

Pairs well with [GST Verification India](https://apify.com/thirdwatch/gst-verification-scraper?fpr=9m2cd6) and [IndiaMart Scraper](https://apify.com/thirdwatch/indiamart-supplier-scraper?fpr=9m2cd6) for full India trade-and-supplier intelligence.

### FAQ

**How fresh is the data?**
Annual data typically lags 1-2 years. Monthly data lags a few months but coverage is thinner.

**Can I query more than two countries at once?**
Each run covers one reporter × partner pair. Chain runs together to build multi-country matrices.

**What HS code granularity is best?**
2-digit gives the biggest categories with the densest coverage. 4-digit is the sweet spot for product-level analysis. 6-digit is most granular but sparser for smaller reporters.

**Do I need an API key?**
No. UN Comtrade's public preview endpoint is used and requires no authentication.

**Can I get monthly breakdowns?**
Yes — set `frequency: "monthly"`. Coverage is thinner than annual.

Last verified: 2026-05

More scrapers at [thirdwatch.dev](https://thirdwatch.dev).

# Actor input Schema

## `reporterCountry` (type: `string`):

The reporting country (who reports the trade). Select from the list or enter a numeric M49 code.

## `partnerCountry` (type: `string`):

The trade partner country. Select from the list or enter a numeric M49 code.

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

Harmonized System code to filter by. Use 2-digit chapter (e.g., '85' for electronics, '84' for machinery), 4-digit heading (e.g., '8517' for telecom equipment), or 6-digit subheading. Leave empty for all chapters.

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

Direction of trade. 'imports' = goods coming INTO the reporter country FROM the partner. 'exports' = goods going OUT of the reporter TO the partner.

## `years` (type: `string`):

Year(s) to fetch data for. Single year: '2023'. Multiple years for trends: '2020,2021,2022,2023'. Available data typically lags 1-2 years.

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

Annual data gives yearly totals. Monthly data gives per-month breakdowns (more records).

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

Maximum number of trade records to return, sorted by trade value descending (top categories first).

## Actor input object example

```json
{
  "reporterCountry": "India",
  "partnerCountry": "China",
  "hsCode": "",
  "flow": "imports",
  "years": "2023",
  "frequency": "annual",
  "maxResults": 25
}
```

# 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 = {
    "reporterCountry": "India",
    "partnerCountry": "China",
    "hsCode": "",
    "flow": "imports",
    "years": "2023",
    "frequency": "annual",
    "maxResults": 25
};

// Run the Actor and wait for it to finish
const run = await client.actor("thirdwatch/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 = {
    "reporterCountry": "India",
    "partnerCountry": "China",
    "hsCode": "",
    "flow": "imports",
    "years": "2023",
    "frequency": "annual",
    "maxResults": 25,
}

# Run the Actor and wait for it to finish
run = client.actor("thirdwatch/trade-data-scraper").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 '{
  "reporterCountry": "India",
  "partnerCountry": "China",
  "hsCode": "",
  "flow": "imports",
  "years": "2023",
  "frequency": "annual",
  "maxResults": 25
}' |
apify call thirdwatch/trade-data-scraper --silent --output-dataset

```

## MCP server setup

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

```

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/hEw8oaOjg8XsMz05X/builds/bKBQiz1quKhk4CZyh/openapi.json
