Find an API

Search public APIs with auth details & Postman guides

← All APIs

UN Comtrade API

comtradeapi.un.org · Government

Government API Key Free Tier Trade Economics Government

United Nations international trade statistics database. Access import/export data for 200+ countries and territories across 6,000+ commodities. Free registration required.

Authentication

API Key authentication Free API key available after registration at comtradeapi.un.org. Pass as Ocp-Apim-Subscription-Key header.

Sample Requests

GET Get trade data

Get total US exports for 2023.

https://comtradeapi.un.org/data/v1/get/C/A/HS?period=2023&cmdCode=TOTAL&flowCode=X&partnerCode=0&reporterCode=842

Hover any highlighted part to learn what it does

Headers — extra info sent with the request
Ocp-Apim-Subscription-Key YOUR_API_KEY
curl -X GET "https://comtradeapi.un.org/data/v1/get/C/A/HS?period=2023&cmdCode=TOTAL&flowCode=X&partnerCode=0&reporterCode=842" \
  -H "Ocp-Apim-Subscription-Key: YOUR_API_KEY"
import requests
params = {
    "period": "2023",
    "cmdCode": "TOTAL",
    "flowCode": "X",
    "partnerCode": "0",
    "reporterCode": "842"
}
headers = {
    "Ocp-Apim-Subscription-Key": "YOUR_API_KEY"
}
response = requests.get(
    "https://comtradeapi.un.org/data/v1/get/C/A/HS",
    params=params,
    headers=headers,
)
print(response.json())
const url = new URL('https://comtradeapi.un.org/data/v1/get/C/A/HS');
url.searchParams.set('period', '2023');
url.searchParams.set('cmdCode', 'TOTAL');
url.searchParams.set('flowCode', 'X');
url.searchParams.set('partnerCode', '0');
url.searchParams.set('reporterCode', '842');

const response = await fetch(url, {
  headers: {
    'Ocp-Apim-Subscription-Key': 'YOUR_API_KEY'
  },
}); 
const data = await response.json();
console.log(data);
package main

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
)

func main() {
	baseURL, _ := url.Parse("https://comtradeapi.un.org/data/v1/get/C/A/HS")
	q := baseURL.Query()
	q.Set("period", "2023")
	q.Set("cmdCode", "TOTAL")
	q.Set("flowCode", "X")
	q.Set("partnerCode", "0")
	q.Set("reporterCode", "842")
	baseURL.RawQuery = q.Encode()
	targetURL := baseURL.String()
	req, _ := http.NewRequest("GET", targetURL, nil)
	req.Header.Set("Ocp-Apim-Subscription-Key", "YOUR_API_KEY")

	client := &http.Client{}
	resp, _ := client.Do(req)
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}
require "net/http"
require "json"

uri = URI("https://comtradeapi.un.org/data/v1/get/C/A/HS")
uri.query = URI.encode_www_form({
  "period" => "2023",
  "cmdCode" => "TOTAL",
  "flowCode" => "X",
  "partnerCode" => "0",
  "reporterCode" => "842"
})

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"

req = Net::HTTP::Get.new(uri)
req["Ocp-Apim-Subscription-Key"] = "YOUR_API_KEY"

res = http.request(req)
puts JSON.parse(res.body)
<?php
$url = "https://comtradeapi.un.org/data/v1/get/C/A/HS?" . http_build_query([
    "period" => "2023",
    "cmdCode" => "TOTAL",
    "flowCode" => "X",
    "partnerCode" => "0",
    "reporterCode" => "842"
]);
$opts = ["http" => [
    "method" => "GET",
    "header" => implode("\r\n", [
        "Ocp-Apim-Subscription-Key: YOUR_API_KEY"
    ]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));

Postman Setup Guide

Get Postman ↗
  1. Register for a free API key at comtradeapi.un.org
  2. Set header: Ocp-Apim-Subscription-Key: YOUR_KEY
  3. reporterCode: ISO numeric country code (842=USA, 826=UK)
  4. flowCode: M=imports, X=exports
  5. cmdCode: TOTAL for all commodities, or HS code for specific goods

What can you build with UN Comtrade API?

UN Comtrade API is a Government API. Developers commonly use government APIs for:

  • surfacing public datasets in citizen-facing apps
  • building transparency and civic engagement tools
  • accessing legislation, court records, and official data
  • powering research and journalism tools
  • creating compliance and regulatory monitoring dashboards

API Key authentication. You'll receive a key after signing up. Send it with every request — in a header or query parameter. Keep it out of client-side code and never commit it to version control. UN Comtrade API is free to use up to a usage limit, making it a low-risk choice to experiment with.

New to APIs? Read our beginner's guide

Open documentation ↗