UN Comtrade Bilateral Trade Statistics Scraper avatar

UN Comtrade Bilateral Trade Statistics Scraper

Pricing

from $0.80 / 1,000 record scrapeds

Go to Apify Store
UN Comtrade Bilateral Trade Statistics Scraper

UN Comtrade Bilateral Trade Statistics Scraper

Pull bilateral merchandise trade statistics from UN Comtrade's official API. Select reporters, trading partners, years, import/export flows and HS commodity detail (chapter to 6-digit); every row ships with human-readable reporter, partner and commodity names plus reported-vs-estimated flags.

Pricing

from $0.80 / 1,000 record scrapeds

Rating

0.0

(0)

Developer

BowTiedRaccoon

BowTiedRaccoon

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

15 hours ago

Last modified

Categories

Share

Bilateral Trade Statistics Database — UN Comtrade

Pull bilateral merchandise trade statistics straight from UN Comtrade, the UN's official global trade database. Returns reporter/partner country pairs, annual or monthly periods, import/export flows, and HS commodity detail from chapter level down to 6-digit subheadings — with every row carrying human-readable country and commodity names instead of raw codes.


UN Comtrade Scraper Features

  • Walks the full reporter x partner x period x flow matrix in one run — pull one country's entire trade book, or the whole dataset, without scripting hundreds of individual queries.
  • Selects any combination of 243 reporting countries and 292 trading partners by name or ISO3 code.
  • Covers both annual and monthly periods, going back decades.
  • Supports Import, Export, Re-Import and Re-Export flows, selectable independently.
  • Returns HS commodity detail at four levels: Total, 2-digit chapter, 4-digit heading, and 6-digit subheading.
  • Ships human-readable reporter, partner, flow, and commodity names on every row — no code lookup tables required on your end.
  • Flags whether a figure was directly reported by the country or estimated/mirrored from its trading partner, so you can tell a filed number from an estimate.

Who Uses UN Comtrade Trade Data?

  • Trade analysts and economists — build country-level import/export models, track trade balances, or study commodity flows over time.
  • Supply chain and sourcing teams — size a country's export capacity for a given HS category before committing to a lane.
  • Import/export compliance teams — cross-check declared trade values against the official record. It's the same database customs brokers reference, minus the manual query-building.
  • Market researchers — quantify a country's dependence on a trading partner for a specific commodity, or spot shifts in trade flows year over year.
  • Journalists and policy researchers — pull the underlying figures behind a trade-balance headline, with the reported-vs-estimated flag attached.
  • Data teams building trade dashboards — feed a structured, joined dataset directly into a BI tool instead of post-processing raw codes.

How the UN Comtrade Scraper Works

  1. Pick your reporters, partners, years, flows, and commodity detail level — or leave any of them blank to include everything available.
  2. The scraper walks every combination of your selections, pacing requests to stay within the data source's rate limits.
  3. Each result is joined against the official reference tables for reporter names, partner names, and commodity descriptions, then saved as a clean row.
  4. The run stops once it hits your maxItems cap or its timeout — pass the resumeCursor from the output back in to keep going from exactly where it left off.

Input

{
"reporters": ["USA"],
"partners": ["CHN"],
"flows": ["M", "X"],
"freqCode": "A",
"classificationLevel": "AG2",
"startYear": 2023,
"endYear": 2023,
"maxItems": 1000
}
FieldTypeDefaultDescription
maxItemsinteger100Maximum records to save. 0 or blank pulls without a cap, bounded only by the run's timeout.
reportersarray[] (all 243)Reporting countries by ISO3 code (e.g. USA, CHN, DEU). Empty means every reporter UN Comtrade publishes.
partnersarray[] (all 292)Trading partners by ISO3 code. Empty means every partner UN Comtrade publishes.
flowsarray["M", "X"]Trade flows: M (Import), X (Export), RM (Re-Import), RX (Re-Export).
freqCodestring"A"A for annual periods, M for monthly.
classificationLevelstring"AG2"Commodity detail: TOTAL, AG2 (HS chapter), AG4 (HS heading), or AG6 (HS subheading).
startYearinteger2023Earliest year to include.
endYearinteger2023Latest year to include (inclusive).

Leaving reporters and partners both blank with the default classificationLevel pulls the full bilateral matrix for the selected years — a large, complete corpus rather than a single lookup.

Resuming a large crawl

Every run emits a resumeCursor value in its Output. To continue a crawl that stopped — because it hit maxItems, a spend cap, or your own timeout — start a new run with the same input plus that resumeCursor. You are not re-charged for records you already received. Resume promptly: the previous run's queue expires with your account's data-retention window.


UN Comtrade Scraper Output Fields

{
"reporter_code": 842,
"reporter_iso": "USA",
"reporter_desc": "USA",
"partner_code": 156,
"partner_iso": "CHN",
"partner_desc": "China",
"period": "2023",
"ref_year": 2023,
"ref_month": 52,
"freq_code": "A",
"flow_code": "M",
"flow_desc": "Import",
"classification_code": "H6",
"cmd_code": "84",
"cmd_desc": "Nuclear reactors, boilers, machinery and mechanical appliances",
"aggr_level": 2,
"is_leaf": false,
"qty": null,
"qty_unit_code": -1,
"qty_unit_abbr": null,
"net_wgt": 12345678.0,
"gross_wgt": null,
"cif_value": 98765432.0,
"fob_value": null,
"primary_value": 98765432.0,
"is_reported": true,
"is_aggregate": false,
"legacy_estimation_flag": 0,
"customs_code": "C00",
"mot_code": 0
}
FieldTypeDescription
reporter_codeintegerUN M49 numeric reporter code.
reporter_isostringReporter ISO3 code.
reporter_descstringReporter country/territory name.
partner_codeintegerUN M49 numeric partner code.
partner_isostringPartner ISO3 code.
partner_descstringPartner country/territory name.
periodstringYYYY for annual, YYYYMM for monthly.
ref_year / ref_monthintegerReference year and month.
freq_codestringA (annual) or M (monthly).
flow_code / flow_descstringImport/Export/Re-Import/Re-Export, code and name.
classification_codestringHS classification vintage in force for this row (e.g. H6).
cmd_code / cmd_descstringCommodity code and name — TOTAL, or an HS chapter/heading/subheading.
aggr_levelintegerDigit-depth of the commodity code (0 = Total, 2/4/6 = HS digits).
is_leafbooleantrue when the commodity code has no finer breakdown beneath it.
qty / qty_unit_abbrnumber/stringQuantity and its unit, when reported.
net_wgt / gross_wgtnumberNet and gross weight in kilograms.
cif_valuenumberCIF value in USD (imports).
fob_valuenumberFOB value in USD (exports).
primary_valuenumberThe primary trade value in USD — CIF for imports, FOB for exports.
is_reportedbooleantrue when the reporter itself filed the figure; false means mirrored/estimated.
is_aggregatebooleantrue when the row is an aggregate rather than a directly reported line.
legacy_estimation_flagintegerUN Comtrade's estimation-method flag.
customs_codestringCustoms procedure code.
mot_codeintegerMode-of-transport code.

FAQ

Does this cover every country UN Comtrade publishes?

Yes — 243 reporting countries/territories and 292 trading partners, including historical entities UN Comtrade still carries in its records. Leave reporters/partners blank to include all of them.

What's the difference between a "reported" and an "estimated" figure?

is_reported tells you whether the country itself filed the trade figure. When it's false, the value was mirrored or estimated from the partner country's own filing — useful for knowing how much to trust a specific number.

Can I pull just one country's entire trade book?

Yes. Set reporters to that one country, leave partners blank, pick a commodity detail level, and set maxItems high (or 0) — the run walks every partner and commodity code for that reporter.

Why does a very detailed (AG6) query sometimes return fewer commodity codes than expected?

Extremely detailed, high-volume bilateral relationships (two large economies at 6-digit HS detail) can occasionally return a partial commodity breakdown for that specific combination — a limit of the free public data tier, not a filter you set.

What's the difference between annual and monthly data?

freqCode: "A" returns one row per year per combination; freqCode: "M" returns one row per calendar month, which multiplies the number of periods by up to 12x for the same year range.


Need More Features?

Have a request — a new field, a bulk-export mode, additional reference joins? Open an issue and we'll take a look.

Why Use This UN Comtrade Scraper?

  • Full bilateral matrix in one run — no scripting hundreds of individual reporter/partner/period queries by hand.
  • Names, not just codes — reporter, partner, and commodity descriptions are joined in on every row.
  • Reported-vs-estimated transparencyis_reported and legacy_estimation_flag let you tell a filed figure from an estimate, which most trade-data tools don't surface at all.