Documentación de la API
Obtenga los datos de UN Comtrade directamente en sus programas: lo que ofrece cada API, cómo llamarla y ejemplos para copiar.
Primeros pasos
-
Obtenga una clave de suscripción
La API pública no necesita clave. Las demás necesitan una clave de suscripción, gratuita con cualquier cuenta, en Mi portal de API.
-
Envíe la clave con cada solicitud
Póngala en este encabezado de la solicitud:
Ocp-Apim-Subscription-Key: su clave de suscripciónO añádala a la dirección como
subscription-key= -
Pruebe una primera solicitud
Esta no necesita clave: ábrala en su navegador o llámela desde su programa.
GET https://comtradeapi.un.org/public/v1/preview/C/A/HS?reporterCode=36&period=2023&partnerCode=0&cmdCode=TOTAL&flowCode=X
Productos de API
-
API pública
Vistas previas de los datos (hasta 500 filas), disponibilidad de datos, publicaciones y listas de referencia, sin clave.
-
API de archivos masivos
Conjuntos de datos completos en archivos comprimidos, uno por declarante y período.
-
API asíncrona
Consultas grandes preparadas en segundo plano; recibe un correo cuando el archivo está listo.
Inicie sesión para ver las API incluidas en su suscripción. Iniciar sesión
Probar
La consola interactiva (Swagger UI) envía solicitudes desde esta página y muestra las respuestas. Elija una API arriba, abra un punto de acceso y luego Try it out; para las API con clave, escriba su clave en Authorize.
La consola es una herramienta de terceros, en inglés, y no es totalmente accesible: todo lo que describe también figura en la referencia de abajo.
API pública
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
- Dirección
https://comtradeapi.un.org/public/v1- Clave de suscripción
- No necesaria
GET
/preview/{typeCode}/{freqCode}/{clCode}
Get Trade Data (limited selection)
| Nombre | Dónde | Obligatorio | Descripción |
|---|---|---|---|
typeCode |
En la ruta | Sí |
Type of trade: C for commodities and S for service
Valores: C, S
|
freqCode |
En la ruta | Sí |
Trade frequency: A for annual and M for monthly
Valores: A, M
|
clCode |
En la ruta | Sí |
Product classifications: HS, SITC, BEC (for goods) or EBOPS (for services).
Valores: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
reporterCode |
En la consulta | No | Reporter code (Possible values are code of the countries separated by comma (,)) |
period |
En la consulta | No | 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 |
En la consulta | No | Partner code (Possible values are code of the countries separated by comma (,)) |
cmdCode |
En la consulta | No | Commodity code. Maximum 1 commodity code for preview |
flowCode |
En la consulta | No | 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. |
Ejemplo de solicitud
GET https://comtradeapi.un.org/public/v1/preview/C/A/HS?reporterCode=36&period=2023&partnerCode=0&cmdCode=TOTAL&flowCode=X
Respuestas
200Success400Invalid or missing parameters.500Unexpected server error.
Ejemplo de respuesta
{
"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)
| Nombre | Dónde | Obligatorio | Descripción |
|---|---|---|---|
typeCode |
En la ruta | Sí |
Type of trade: C for commodities and S for service
Valores: C, S
|
freqCode |
En la ruta | Sí |
Trade frequency: A for annual and M for monthly
Valores: A, M
|
clCode |
En la ruta | Sí |
Product classifications: HS (for goods).
Valores: HS, H6, H5, H4, H3, H2, H1, H0
|
reporterCode |
En la consulta | No | Reporter code (Possible values are code of the countries separated by comma (,)) |
period |
En la consulta | No | 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 |
En la consulta | No | Partner code (Possible values are code of the countries separated by comma (,)) |
partner2Code |
En la consulta | No | Second partner/consignment code (Possible values are code of the countries separated by comma (,)) |
cmdCode |
En la consulta | No | Commodity code. Multi value input should be in the form of csv (Codes separated by comma (,)) |
flowCode |
En la consulta | No | 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 |
En la consulta | No | 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 |
En la consulta | No | 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. |
Ejemplo de solicitud
GET https://comtradeapi.un.org/public/v1/previewTariffline/C/A/HS?reporterCode=36&period=2023&partnerCode=0&cmdCode=TOTAL&flowCode=X
Respuestas
200Success400Invalid or missing parameters.500Unexpected server error.
Ejemplo de respuesta
{
"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
Ejemplo de solicitud
GET https://comtradeapi.un.org/public/v1/getComtradeReleases
Respuestas
200Success500Unexpected server error.
Ejemplo de respuesta
{
"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
| Nombre | Dónde | Obligatorio | Descripción |
|---|---|---|---|
typeCode |
En la ruta | Sí |
Valores: C, S
|
freqCode |
En la ruta | Sí |
Valores: A, M
|
clCode |
En la ruta | Sí |
Valores: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
Ejemplo de solicitud
GET https://comtradeapi.un.org/public/v1/getMetadata/C/A/HS
Respuestas
200Success400Invalid or missing parameters.500Unexpected server error.
Ejemplo de respuesta
{
"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
| Nombre | Dónde | Obligatorio | Descripción |
|---|---|---|---|
typeCode |
En la ruta | Sí |
Valores: C, S
|
freqCode |
En la ruta | Sí |
Valores: A, M
|
clCode |
En la ruta | Sí |
Valores: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
Ejemplo de solicitud
GET https://comtradeapi.un.org/public/v1/getDA/C/A/HS
Respuestas
200Success400Invalid or missing parameters.500Unexpected server error.
Ejemplo de respuesta
{
"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
| Nombre | Dónde | Obligatorio | Descripción |
|---|---|---|---|
typeCode |
En la ruta | Sí |
Valores: C, S
|
freqCode |
En la ruta | Sí |
Valores: A, M
|
clCode |
En la ruta | Sí |
Valores: HS, H6, H5, H4, H3, H2, H1, H0, S4, S3, S2, S1, BE, BE5, EB, EB10, EB02, EBS
|
Ejemplo de solicitud
GET https://comtradeapi.un.org/public/v1/getDATariffline/C/A/HS
Respuestas
200Success400Invalid or missing parameters.500Unexpected server error.
Ejemplo de respuesta
{
"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-)
| Nombre | Dónde | Obligatorio | Descripción |
|---|---|---|---|
series_type |
En la consulta | No |
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.
Valores: T35.Q.V.$, T35.A.V.$, T38.Q.CF., T38.A.CF., T35.M.V.$, T38.M.CF.
|
year |
En la consulta | No | Reference year (default = any):The reference year of period. As an example: 2015,2016 |
country_code |
En la consulta | No | Country code (Possible values are code of the countries separated by comma (,)) |
period |
En la consulta | No | 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 |
En la consulta | No |
data set frequency: Valid values:
A Annual
Q Quarterly
M Monthly
Valores: A, Q, M
|
table_type |
En la consulta | No |
(default = any) MBS Table numbers: MBS and ITSY table identifier.
Valores: T35, T38
|
format |
En la consulta | No |
Output format (default = json): Valid value are json, txt or csv
Valores: csv, txt, json
|
Ejemplo de solicitud
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
Respuestas
200Success (JSON by default; CSV/TXT when format is set)400Invalid or missing parameters.500Unexpected server error.
Ejemplo de respuesta
{
"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": ""
}