Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

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

Apify Actor Run on Apify No API key Pay per result Export

▶️ Run the Import Export Trade Data Scraper on Apify →

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 reporter country, trading partner, HS commodity code, trade value (USD), quantity and net weight — annual or monthly, with no API key, no login and no registration. Just enter plain country names like Germany, China or USA and the Actor resolves them to the correct UN M49 codes, handles throttling and pagination, and streams thousands of trade-flow rows into a tidy dataset.

This repository is the documentation and usage guide for the hosted Apify Actor. The Actor runs entirely on Apify — there is nothing to install and no source to build. Open it, pick your countries and commodities, and export the data.


✨ What you get

One row per reporter × partner × commodity × period × flow, with a full value and volume breakdown:

  • 🌍 Any country pair — one or many reporter countries × one or many partners, or World (all partners combined) and all.
  • 🔤 Plain names or codes — pass USA, Germany, China or numeric M49 codes (842, 276); names resolve to M49 automatically.
  • 📦 HS commodity granularity — specific HS codes (8703, 8517) or an aggregation: TOTAL, AG2 (HS2 chapters), AG4 (headings), AG6 (subheadings).
  • 🔁 Import, export or both — pick the trade-flow direction you need.
  • 📅 Annual or monthly — a single year, a list, a range, or a monthly range like 202301-202312.
  • 💵 Full value breakdown — trade value in USD plus CIF (imports) and FOB (exports), net weight in kg, quantity and unit.
  • 🗺️ ISO3 codes included — every row carries reporter and partner ISO3 codes for easy joins and mapping.

💡 Use cases

  • Market-entry research — see which countries buy a product and how much before you enter a market.
  • Supplier & sourcing discovery — find where a country imports a commodity from, and in what volume.
  • Commodity trade trend analysis — track import/export value over years or months by HS code.
  • Supply-chain & tariff impact modelling — model how bilateral flows shift over time.
  • Economics & BI dashboards — feed clean bilateral trade statistics into reports and visualizations.
  • Trade-balance monitoring — compare a country's imports vs. exports with a specific partner.
  • AI agents & data products — supply structured international trade data to LLM workflows and datasets.

🚀 Quick start

1) Apify Console (no code)

  1. Open the Actor: apify.com/logiover/comtrade-trade-data-scraper
  2. Click Try for free.
  3. The defaults (USA reporter, World partner, AG2 commodities, last full year) return a working dataset immediately — or set your own countries, commodities, flow and period.
  4. Click Start, then Export the dataset to JSON / CSV / Excel from the Output tab.

2) Apify CLI

npm i -g apify-cli
apify login
apify call logiover/comtrade-trade-data-scraper \
  --input '{ "reporters": "USA, Germany", "partners": "China", "flow": "import", "commodities": "AG2", "periods": "2022-2023" }'

3) API / cURL

curl -X POST "https://api.apify.com/v2/acts/logiover~comtrade-trade-data-scraper/run-sync-get-dataset-items?token=YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "reporters": "USA", "partners": "China", "flow": "import", "commodities": "AG2", "periods": "2023" }'

4) JavaScript (apify-client)

import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_TOKEN' });

const run = await client.actor('logiover/comtrade-trade-data-scraper').call({
  reporters: 'USA, Germany',
  partners: 'China',
  flow: 'import',
  commodities: 'AG2',
  periods: '2022-2023',
  maxResults: 1000,
});

const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items);

5) Python (apify-client)

from apify_client import ApifyClient

client = ApifyClient("YOUR_TOKEN")

run = client.actor("logiover/comtrade-trade-data-scraper").call(run_input={
    "reporters": "China",
    "partners": "USA, Germany, Japan",
    "flow": "export",
    "commodities": "8517,8542",
    "periods": "2023",
})

for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item["reporter"], "→", item["partner"], item["hsCode"], item["tradeValueUsd"])

More detailed snippets live in examples/.

📥 Input

All fields are optional — the defaults return a working dataset out of the box.

Field Type Default Description
reporters string (dropdown or free text) 842 (USA) Reporting country/countries — pick from the list, or type plain names, M49 codes, comma-separated (USA, Germany / 842,276) or all.
partners string (dropdown or free text) 0 (World) Trading partner(s) — World (all partners combined), a specific country, comma-separated list, or all.
flow string (dropdown) both import, export or both.
commodities string (dropdown or free text) AG2 Specific HS codes (8703,8517) or an aggregation: TOTAL, AG2 (HS2 chapters), AG4 (headings), AG6 (subheadings).
periods string (dropdown or free text) last full year Year 2023, list 2021,2022, range 2020-2023, or monthly 202301-202312.
frequency string (dropdown) A A (annual) or M (monthly).
maxResults integer 1000 Maximum trade records to save. Raise to pull more; keeps broad queries fast and cheap.
throttleMs integer 1100 Delay between calls (ms). The keyless tier rate-limits ~1 req/sec — keep ≥ 1100.
proxyConfiguration object Apify Proxy on Proxy settings; the Actor also falls back to a direct connection on its final retry.

Tip — you rarely need M49 codes. Just type the country name (Germany, Republic of Korea, Viet Nam) and it maps to the UN M49 numeric code. Use World as the partner to get each reporter's total trade with all partners in one row, or all to expand every bilateral pair. reporters, partners, flow, commodities, periods and frequency are dropdowns in the Console.

📤 Output

Exportable to JSON, CSV, JSONL, Excel or XML. Fields:

Field Description
reporter / reporterISO / reporterCode Reporting country name, ISO3 code and numeric M49 code.
flow Trade flow direction — Import, Export, re-export, etc.
partner / partnerISO / partnerCode Partner country name (or World), ISO3 code and M49 code.
period / year Reporting period (YYYY or YYYYMM) and reference year as a number.
hsCode / commodity / classification HS commodity code, description, and classification code.
tradeValueUsd Primary trade value in US dollars.
cifValueUsd CIF value (cost, insurance, freight) — for imports, when reported.
fobValueUsd FOB value (free on board) — for exports, when reported.
netWeightKg Net weight in kilograms.
qty / qtyUnit Traded quantity and its unit of measure.
isAggregate Whether the row is an aggregated total.
scrapedAt ISO timestamp when the row was fetched.

Sample JSON

{
  "reporter": "USA",
  "reporterISO": "USA",
  "reporterCode": 842,
  "flow": "Import",
  "partner": "China",
  "partnerISO": "CHN",
  "partnerCode": 156,
  "period": "2023",
  "year": 2023,
  "hsCode": "85",
  "commodity": "Electrical machinery and equipment",
  "tradeValueUsd": 127845300000,
  "cifValueUsd": 127845300000,
  "fobValueUsd": null,
  "netWeightKg": 4120500000,
  "qty": null,
  "qtyUnit": "N/A",
  "classification": "HS",
  "isAggregate": false,
  "scrapedAt": "2026-07-12T08:30:11.000Z"
}

🔌 Integrations & automation

  • Schedulesschedule monthly or quarterly runs to refresh your trade datasets as new UN Comtrade periods are released.
  • Webhooks — trigger a downstream job or Slack alert on run completion.
  • Google Sheets / Amazon S3 / databases — push the dataset to Sheets, S3 or your own DB via Apify integrations.
  • Zapier · Make · n8n · Pipedream — build automated trade-intelligence pipelines.
  • API access — pull results in JSON, CSV, XLSX or JSONL via the Apify dataset API.

📦 Export formats

CSV · JSON · JSONL · Excel (XLSX) · XML — from the Console Export button or the Apify API.

❓ 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. Only an Apify account is required.

Does UN Comtrade have a public API — is this an API alternative?

UN Comtrade exposes a raw data API that normally involves key registration, M49 code lookups, throttling and pagination handling. This Actor is an unofficial UN Comtrade API alternative that does all of that for you and returns tidy rows.

Can I use plain country names instead of M49 codes?

Yes. Pass names like Germany, China, USA, Republic of Korea and the Actor resolves them to the correct UN M49 codes automatically. Numeric M49 codes also work.

What are AG2, AG4 and 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, or TOTAL for the all-commodities total.

How do I find which countries import a product by HS code?

Set the partner to World and enter the HS code as commodities; the scraper returns each reporter country's import value and quantity for that product.

Can I get monthly trade data instead of annual figures?

Yes. Set frequency to M and pass a monthly range like 202301-202312 to pull month-by-month bilateral trade flows.

How do I export UN Comtrade data to CSV or Excel?

Run the Actor and download the dataset as CSV, JSON, Excel or JSONL from the Console, or fetch it through the Apify API. Every row is one reporter × partner × HS code × period × flow record.

How much data can I get in one run?

Thousands of trade-flow rows. The keyless preview tier caps records per single query and rate-limits to ~1 request/second, so the Actor throttles (keep throttleMs ≥ 1100) and fans out across countries, commodities and periods. For very broad jobs (e.g. all reporters over many years), split into smaller runs.

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 individual company records.

Is it legal to scrape UN Comtrade data?

The Actor collects publicly available official trade statistics from UN Comtrade's preview tier. It is an independent scraper, not affiliated with or endorsed by the United Nations. You are responsible for using the data in compliance with UN Comtrade's terms and applicable laws.

🔗 Related actors by logiover

👉 Browse all logiover scrapers on Apify Store.


📄 Documentation only — this repository contains no scraper source code. The Actor runs on the Apify platform. ▶️ Run it: apify.com/logiover/comtrade-trade-data-scraper

Licensed under the MIT License · © 2026 logiover

About

Import Export Trade Data Scraper — global UN Comtrade bilateral trade statistics by country, HS code & period. No API key, export CSV/JSON. Docs for the Apify Actor.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors