TSB logo

Data Extraction Using Comtrade Web Service

Web services

This web services is no longer being improved. It is replaced by API .v.2:

Data Extraction Using Comtrade Web Service
General Information

Comtrade Web Service is a REST Web Service (see so that data extraction requests need the right URL to be submitted.

Data, metadata (such as explanatory notes) and data availability can be accessible within web service framework.

Data Format

The web service offers two kinds: SDMX (see and element-based-XML. Depending on what you need, both formats can be used independently.

In order to promote SDMX format, command line data extraction program was created (ComtradeTools). You can use it to extract data and metadata within SDMX and save it as CSV text format.

SDMX vs. Element-Based-XML

SDMX merges data and metadata information in one XML file. For an example, exchange rate and trade system (both of them are metadata) are included on data header. Due to its complexity, SDMX might require extensive learning effort.

On the other hand, element-based-XML is a very simple format, on which it can also be imported easily with other spreadsheets or databases, such as Microsoft Excel. However, metadata may not integrated with data.

Note: Complex query which includes commodity/country grouping is only available on element-based-XML.

Security & Authentication

Access to UN Comtrade database is restricted with IP authentication. A user must have site license account in UN Comtrade and Web Service access right is granted. However, access to metadata and data availability is not restricted.

(Feb 2010) For those who like to access UN Comtrade Web Service outside of IP address ranges, you can use the authorization code (can be obtained from

Click here to check your access rights:

Web Service Methods and Parameters

To access REST web service, you need page name (method) and query string (parameter). In fact, UN Comtrade database was built based on query string, such result page of Ireland Total Export in 2006

dqBasicQueryResults.aspx is the page name (method to show result) and cc=TOTAL&px=H2&r=372&y=2006 are the query strings, of which cc is commodity code, px is commodity classification, r is reporter and y is year.

In order to get the result via web service, you need to change dqBasicQueryResults.aspx to get.aspx (for Element-Based-XML format) or getSdmxV1.aspx (for SDMX format) and change /db to /ws (web service) and add comp=false (set compression flag to disable, so that it can be viewed on a browser):
( or
or for those who like to use authorization code

Here is the list of common query string parameters:

Px = Commodity Classification
R = Reporter
Y = Year
CC = Commodity Code
P = Partner Country
Rg = Trade Flow

Data (restricted access)

The following data is available (depends on your access rights):

-UN Comtrade (get.aspx, getSdmxV1.aspx)
-TotalTrade (getTTotal.aspx, getConvFactor.aspx)
-Tariff Line (getSdmxTariffLineV1.aspx)

Metadata and data availability (free access)

Reference Tables:
-Country List (refs/getCountryList.aspx)
-Commodity List (refs/getCommodityList.aspx)
URL examples:
-Get 2 digit HS1996:
-Get all country codes:

-Explanatory Notes (refs/getExplanatoryNotes.aspx)

Data Availability
-Data Availability (refs/getDataAvailablity.aspx)

Related Links

Also In This Category

Add Your Comments
Comments require login or registration.
Last Modified: 2 Years Ago
Last Modified By: Buenavad
Rated 2 stars based on 3 votes.
Article has been viewed 46.7K times.
Find Similar