API 文档
将联合国商品贸易统计数据直接导入您的程序:每个 API 提供什么、如何调用,以及可复制的示例。
入门
-
获取订阅密钥
公共 API 无需密钥。其他 API 需要订阅密钥,任何帐户均可在“我的 API 门户”免费获取。
-
每个请求都附上密钥
将其放入此请求头:
Ocp-Apim-Subscription-Key: 您的订阅密钥或作为以下参数添加到地址中
subscription-key= -
尝试第一个请求
此请求无需密钥:可在浏览器中打开,或从您的程序调用。
GET https://comtradeapi.un.org/public/v1/preview/C/A/HS?reporterCode=36&period=2023&partnerCode=0&cmdCode=TOTAL&flowCode=X
API 产品
-
公共 API
无需密钥即可获取贸易数据预览(最多 500 行)、数据可用性、发布和参考列表。
-
批量 API
以压缩文件提供的完整数据集,每个报告方和时期一个。
-
异步 API
大型查询在后台准备;文件就绪时您会收到电子邮件。
登录即可查看您的订阅所含的 API。 登录
试用
交互式控制台 (Swagger UI) 从本页发送请求并显示响应。在顶部选择一个 API,打开一个端点,然后点击 Try it out;对于需要密钥的 API,请在 Authorize 中输入密钥。
控制台是第三方工具,仅有英文版,且不完全无障碍:其所述内容在下方参考中均有说明。
公共 API
Free API to preview trade data. Results are limited to 500 records. No subscription key required. See examples at https://unstats.un.org/go/498d8e
- 地址
https://comtradeapi.un.org/public/v1- 订阅密钥
- 不需要
GET
/preview/{typeCode}/{freqCode}/{clCode}
Get Trade Data (limited selection)
| 名称 | 位置 | 必填 | 说明 |
|---|---|---|---|
typeCode |
路径中 | 是 |
Type of trade: C for commodities and S for service
取值: C, S
|
freqCode |
路径中 | 是 |
Trade frequency: A for annual and M for monthly
取值: A, M
|
clCode |
路径中 | 是 |
Product classifications: HS, SITC, BEC (for goods) or EBOPS (for services).
取值: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
reporterCode |
查询中 | 否 | Reporter code (Possible values are code of the countries separated by comma (,)) |
period |
查询中 | 否 | Year or month. Year should be 4 digit year. Month should be six digit integer with the values of the form YYYYMM. Ex: 201002 for 2010 February. Maximum 1 period for preview |
partnerCode |
查询中 | 否 | Partner code (Possible values are code of the countries separated by comma (,)) |
cmdCode |
查询中 | 否 | Commodity code. Maximum 1 commodity code for preview |
flowCode |
查询中 | 否 | Trade flow code. Multi value input should be in the form of csv (Codes separated by comma (,)) Allowed values (case-insensitive): M, X, RX, RM, MIP, XIP, MOP, XOP, MIF, XIF, DX, FM. Omit to not filter. |
请求示例
GET https://comtradeapi.un.org/public/v1/preview/C/A/HS?reporterCode=36&period=2023&partnerCode=0&cmdCode=TOTAL&flowCode=X
响应
200Success400Invalid or missing parameters.500Unexpected server error.
响应示例
{
"elapsedTime": "1.07 secs",
"count": 1,
"data": [
{
"typeCode": "C",
"freqCode": "A",
"refPeriodId": 20220101,
"refYear": 2022,
"refMonth": 52,
"period": "2022",
"reporterCode": 842,
"reporterISO": null,
"reporterDesc": null,
"flowCode": "M",
"flowDesc": null,
"partnerCode": 0,
"partnerISO": null,
"partnerDesc": null,
"partner2Code": 0,
"partner2ISO": null,
"partner2Desc": null,
"classificationCode": "H6",
"classificationSearchCode": "HS",
"isOriginalClassification": true,
"cmdCode": "TOTAL",
"cmdDesc": null,
"aggrLevel": null,
"isLeaf": null,
"customsCode": "C00",
"customsDesc": null,
"mosCode": "0",
"motCode": 0,
"motDesc": null,
"qtyUnitCode": -1,
"qtyUnitAbbr": null,
"qty": 0.0,
"isQtyEstimated": false,
"altQtyUnitCode": -1,
"altQtyUnitAbbr": null,
…
GET
/previewTariffline/{typeCode}/{freqCode}/{clCode}
Get Tariffline Data (limited selection)
| 名称 | 位置 | 必填 | 说明 |
|---|---|---|---|
typeCode |
路径中 | 是 |
Type of trade: C for commodities and S for service
取值: C, S
|
freqCode |
路径中 | 是 |
Trade frequency: A for annual and M for monthly
取值: A, M
|
clCode |
路径中 | 是 |
Product classifications: HS (for goods).
取值: HS, H6, H5, H4, H3, H2, H1, H0
|
reporterCode |
查询中 | 否 | Reporter code (Possible values are code of the countries separated by comma (,)) |
period |
查询中 | 否 | Year or month. Year should be 4 digit year. Month should be six digit integer with the values of the form YYYYMM. Ex: 201002 for 2010 February. Multi value input should be in the form of csv (Codes separated by comma (,)) |
partnerCode |
查询中 | 否 | Partner code (Possible values are code of the countries separated by comma (,)) |
partner2Code |
查询中 | 否 | Second partner/consignment code (Possible values are code of the countries separated by comma (,)) |
cmdCode |
查询中 | 否 | Commodity code. Multi value input should be in the form of csv (Codes separated by comma (,)) |
flowCode |
查询中 | 否 | Trade flow code. Multi value input should be in the form of csv (Codes separated by comma (,)) Allowed values (case-insensitive): M, X, RX, RM, MIP, XIP, MOP, XOP, MIF, XIF, DX, FM. Omit to not filter. |
customsCode |
查询中 | 否 | Customs code. Multi value input should be in the form of csv (Codes separated by comma (,)) Allowed values: C00, C01, C02, C03, C04, C05, C06, C07, C08, C09, C10, C11, C12, C13, C14, C15, C20. Omit to not filter. |
motCode |
查询中 | 否 | Mode of transport code. Multi value input should be in the form of csv (Codes separated by comma (,)) Allowed values: 0, 1000, 2000, 2100, 2200, 2900, 3000, 3100, 3200, 3900, 9000, 9100, 9110, 9120, 9190, 9200, 9300, 9900. Omit to not filter. |
请求示例
GET https://comtradeapi.un.org/public/v1/previewTariffline/C/A/HS?reporterCode=36&period=2023&partnerCode=0&cmdCode=TOTAL&flowCode=X
响应
200Success400Invalid or missing parameters.500Unexpected server error.
响应示例
{
"elapsedTime": "38.07 secs",
"count": 1,
"data": [
{
"typeCode": "C",
"freqCode": "M",
"refPeriodId": 20230101,
"period": 202301,
"reporterCode": 36,
"reporterDesc": null,
"reporterISO": null,
"flowCode": "X",
"flowDesc": null,
"partnerCode": 344,
"partnerDesc": null,
"partnerISO": null,
"partner2Code": -1,
"partner2Desc": null,
"partner2ISO": null,
"classificationCode": "H6",
"cmdCode": "010121",
"cmdDesc": null,
"customsCode": "-1",
"customsDesc": null,
"mosCode": "-1",
"motCode": 9900,
"motDesc": null,
"qtyUnitCode": 5,
"qtyUnitAbbr": null,
"qty": 10.0,
"altQtyUnitCode": 5,
"altQtyUnitAbbr": null,
"altQty": 10.0,
"netWgt": 0.0,
"grossWgt": 5000.0,
"cifvalue": 0.0,
"fobvalue": 2739872.41,
"primaryValue": 2739872.41
}
…
GET
/getComtradeReleases
Get list of recent data releases
请求示例
GET https://comtradeapi.un.org/public/v1/getComtradeReleases
响应
200Success500Unexpected server error.
响应示例
{
"elapsedTime": "0.33 secs",
"count": 1,
"data": [
{
"reporterCode": 364,
"flagCode": "IR",
"datasetDesc": "Iran CA 2023",
"nr": "N",
"dateRelease": "2026-09-24T00:00:00"
}
],
"error": ""
}
GET
/getMetadata/{typeCode}/{freqCode}/{clCode}
Get Metadata (i.e., exchange rate, publication notes) for specific datasets
| 名称 | 位置 | 必填 | 说明 |
|---|---|---|---|
typeCode |
路径中 | 是 |
取值: C, S
|
freqCode |
路径中 | 是 |
取值: A, M
|
clCode |
路径中 | 是 |
取值: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
请求示例
GET https://comtradeapi.un.org/public/v1/getMetadata/C/A/HS
响应
200Success400Invalid or missing parameters.500Unexpected server error.
响应示例
{
"elapsedTime": "0.01 secs",
"count": 1,
"data": [
{
"reporterCode": 842,
"period": 2022,
"typeCode": "C",
"freqCode": "A",
"datasetCode": 20842202201202100,
"notes": [
{
"datasetCode": 20842202201202100,
"typeCode": "C",
"freqCode": "A",
"period": 2022,
"reporterCode": 842,
"reporterDescription": "USA",
"currency": "USD",
"importConvFactor": "1",
"exportConvFactor": "1",
"tradeSystem": "General",
"classificationCode": "H6",
"importValuation": "CIF",
"exportValuation": "FOB",
"importPartnerCountry": "Origin",
"exportPartnerCountry": "Last Known Destination",
"importPartner2Country": "N/A",
"exportPartner2Country": "N/A",
"publicationNote": "New Data: Data for this period is published for the first time; the new data was collected from US Census Bureau on 09 Feb 23.",
"publicationDate": "2023-03-09T17:58:13.15",
"publicationDateShort": "2023-03-09"
}
]
}
],
"error": ""
}
GET
/getDA/{typeCode}/{freqCode}/{clCode}
Get Trade Data Availability
| 名称 | 位置 | 必填 | 说明 |
|---|---|---|---|
typeCode |
路径中 | 是 |
取值: C, S
|
freqCode |
路径中 | 是 |
取值: A, M
|
clCode |
路径中 | 是 |
取值: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
请求示例
GET https://comtradeapi.un.org/public/v1/getDA/C/A/HS
响应
200Success400Invalid or missing parameters.500Unexpected server error.
响应示例
{
"elapsedTime": "0.12 secs",
"count": 1,
"data": [
{
"datasetCode": 20842202201202100,
"typeCode": "C",
"freqCode": "A",
"period": 2022,
"reporterCode": 842,
"reporterISO": "USA",
"reporterDesc": "USA",
"classificationCode": "H6",
"classificationSearchCode": "HS",
"isOriginalClassification": true,
"isExtendedFlowCode": true,
"isExtendedPartnerCode": true,
"isExtendedPartner2Code": false,
"isExtendedCmdCode": true,
"isExtendedCustomsCode": false,
"isExtendedMotCode": false,
"totalRecords": 1210614,
"datasetChecksum": 1750866618,
"firstReleased": "2023-03-09T19:23:39.45",
"lastReleased": "2023-03-09T19:23:39.45"
}
],
"error": ""
}
GET
/getDATariffline/{typeCode}/{freqCode}/{clCode}
Get Tariffline Data Availability
| 名称 | 位置 | 必填 | 说明 |
|---|---|---|---|
typeCode |
路径中 | 是 |
取值: C, S
|
freqCode |
路径中 | 是 |
取值: A, M
|
clCode |
路径中 | 是 |
取值: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
请求示例
GET https://comtradeapi.un.org/public/v1/getDATariffline/C/A/HS
响应
200Success400Invalid or missing parameters.500Unexpected server error.
响应示例
{
"elapsedTime": "0.06 secs",
"count": 1,
"data": [
{
"datasetCode": 30036202301202100,
"typeCode": "C",
"freqCode": "M",
"period": 202301,
"reporterCode": 36,
"reporterISO": "AUS",
"classificationCode": "H6",
"isOriginalClassification": true,
"isExtendedFlowCode": false,
"isExtendedPartnerCode": true,
"isExtendedPartner2Code": false,
"isExtendedCmdCode": true,
"isExtendedCustomsCode": false,
"isExtendedMotCode": true,
"totalRecords": 250125,
"datasetChecksum": 1356064231,
"lengthCmdCode": 6,
"firstReleased": "2023-04-27T00:23:19.56",
"lastReleased": "2024-03-14T08:42:10.66"
}
],
"error": ""
}
GET
/getMBS
The MBS data API gives users access to historical time series of MBS trade tables, notably Tables 38 and 35. Data availability and frequency of update depend on data series. T35 Total trade - value (1946-) T38 Conversion factors (1946-)
| 名称 | 位置 | 必填 | 说明 |
|---|---|---|---|
series_type |
查询中 | 否 |
Combination of table number, frequency, type of measurement and currenty. T35.Q.V.$ T35.A.V.$ T38.Q.CF. T38.A.CF. T35.M.V.$ T38.M.CF.
取值: T35.Q.V.$, T35.A.V.$, T38.Q.CF., T38.A.CF., T35.M.V.$, T38.M.CF.
|
year |
查询中 | 否 | Reference year (default = any):The reference year of period. As an example: 2015,2016 |
country_code |
查询中 | 否 | Country code (Possible values are code of the countries separated by comma (,)) |
period |
查询中 | 否 | Year or month. Year should be 4 digit year. Month should be six digit integer with the values of the form YYYYMM. Ex: 201002 for 2010 February. Multi value input should be in the form of csv (Codes separated by comma (,)) |
period_type |
查询中 | 否 |
data set frequency: Valid values:
A Annual
Q Quarterly
M Monthly
取值: A, Q, M
|
table_type |
查询中 | 否 |
(default = any) MBS Table numbers: MBS and ITSY table identifier.
取值: T35, T38
|
format |
查询中 | 否 |
Output format (default = json): Valid value are json, txt or csv
取值: csv, txt, json
|
请求示例
GET https://comtradeapi.un.org/public/v1/getMBS?series_type=T35.A.V.%24&year=2023&country_code=36&period=2023&period_type=A&table_type=T35
响应
200Success (JSON by default; CSV/TXT when format is set)400Invalid or missing parameters.500Unexpected server error.
响应示例
{
"elapsedTime": "1.72 secs",
"count": 1,
"data": [
{
"series_Type": "T35.A.V.$",
"table_Type": "T35",
"table_Type_Desc": "Total trade - value",
"country_Code": 842,
"country_Type": "C",
"country_English_Name": "United States",
"year": 2022,
"period_Type": "A",
"period_Number": 0,
"period": "202252",
"period_In_Date": "01/01/2022",
"trade_Flow": "X",
"trade_Flow_Desc": "Exports",
"commodity_Classification": "",
"commodity_Group_Code": "1",
"commodity_Group_Name": "Total",
"partner_Country_Code": 0,
"partner_Country_English_Name": "World",
"base_Year": null,
"currency_Type": "$",
"value": 2065156.971,
"value_Unit": "M",
"value_Type": "V",
"value_Type_Desc": "Value",
"estimation_Type": "A",
"estimation_Type_Desc": "Actual"
}
],
"error": ""
}