UN Comtrade Trade Data Query
comtrade.trade.queryQuery UN Comtrade import/export statistics by country, period, commodity, and partner to retrieve merchandise trade records.
Instructions
Query international merchandise trade statistics from the UN Comtrade database. Returns up to 500 records of imports and/or exports for a specific reporting country, reference period, commodity code, and partner country. Data covers 200+ reporter countries from 1962 (annual) and 2010 (monthly). Values in USD (primary value), CIF for imports, FOB for exports. Commodities classified by Harmonized System (HS) or SITC. Use reporter_code from comtrade.reporters, HS chapter codes (e.g. "84" for machinery, "27" for petroleum, "85" for electronics), and flow_code M=imports, X=exports. Source: UN Comtrade public preview API, no auth, 500 calls/day free.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| period | Yes | Reference period to query. Annual: 4-digit year (e.g. "2022"). Monthly: YYYYMM (e.g. "202209" for Sep 2022). Comma-separated for multiple periods (e.g. "2020,2021,2022"). | |
| cmd_code | No | Commodity code filter. Use HS codes (e.g. "84" for machinery, "27" for petroleum, "TOTAL" for aggregate totals, "AG2" for all 2-digit chapters). Omit to return all commodities (may be large). Default: TOTAL. | |
| flow_code | Yes | Trade flow direction. M=Imports, X=Exports, MX=Both imports and exports, RM=Re-imports, RX=Re-exports. | |
| freq_code | No | Frequency. A=Annual (default), M=Monthly. | |
| type_code | No | Trade data type. C=Commodities (default), S=Services. | |
| max_records | No | Maximum number of records to return (1–500). Default 100. The public preview API is capped at 500 records per request. | |
| aggregate_by | No | Aggregate results by a dimension. Valid values: "cmdCode", "flowCode", "partnerCode", "reporterCode", "period". Omit to return unaggregated records. | |
| customs_code | No | Customs procedure code filter (e.g. "C00"=all procedures, "C03"=outright export, "C04"=warehousing). Omit for all procedures. | |
| partner_code | No | UN numeric code for the partner country. 0=World aggregate (all partners combined). Omit to return all individual partners. | |
| partner2_code | No | Secondary partner code for extended trade flow tracking (consignment country). 0=World aggregate. Omit to use the default world aggregate. | |
| reporter_code | Yes | UN numeric code for the reporting country (e.g. 276=Germany, 840=USA, 156=China, 826=UK). Use comtrade.reporters to look up codes. | |
| classification | No | Commodity classification system. HS=Harmonized System (default, most common). B4/B5=BEC, EB=EBOPS services, S1-S4/SS=SITC revisions. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| error | No | Present only when the call failed. Includes error code, message, request_id, and any provider-specific extras. | |
| result | No | Tool response payload. Shape varies per tool — consult the tool description and inputSchema. May be an object, array, string, or number depending on the upstream provider response. |