GEO Country List

Retrieve a comprehensive list of countries with customizable field selection including ISO codes and country names

Overview

This endpoint provides access to a complete list of all countries with their ISO 3166-1 codes. You can customize which fields to include in the response, making it flexible for different use cases.

The endpoint returns:

  • Complete list of 249 countries and territories
  • ISO 3166-1 alpha-2 codes (e.g., "US", "GB")
  • ISO 3166-1 alpha-3 codes (e.g., "USA", "GBR")
  • ISO 3166-1 numeric codes (e.g., "840", "826")
  • Official English country names
  • Customizable field selection

Pricing

📊 1 Credit per Request

Each request costs 1 data credit and counts as a billable request.

Endpoint

GET /geo/country
GET /geo/country?keys=name,c2,c3,numeric

Query Parameters

ParameterTypeRequiredDescription
keysstringNoComma-separated list of fields to include in response. Valid values: name, c2, c3, numeric. Default: name
langstringNoLanguage code for country name translations (ISO 639-1). Default: en. See Supported Languages

Response Format

Default Response (name only)

[
  { "name": "Afghanistan" },
  { "name": "Albania" },
  { "name": "Algeria" },
  ...
]

Full Response (all fields)

[
  {
    "name": "Afghanistan",
    "c2": "AF",
    "c3": "AFG",
    "numeric": "004"
  },
  {
    "name": "Albania",
    "c2": "AL",
    "c3": "ALB",
    "numeric": "008"
  },
  ...
]

Response Fields

FieldTypeDescription
namestringOfficial English name of the country
c2stringISO 3166-1 alpha-2 country code (2 letters)
c3stringISO 3166-1 alpha-3 country code (3 letters)
numericstringISO 3166-1 numeric code (3 digits, zero-padded)

Example Requests

Get All Country Names

curl -X GET "https://api.boxapi.com/geo/country" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Get Countries with ISO Codes

curl -X GET "https://api.boxapi.com/geo/country?keys=name,c2,c3" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Get All Available Fields

curl -X GET "https://api.boxapi.com/geo/country?keys=name,c2,c3,numeric" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Get Countries in Different Languages

# Get country names in Spanish
curl -X GET "https://api.boxapi.com/geo/country?lang=es" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

# Get countries in French with all fields
curl -X GET "https://api.boxapi.com/geo/country?keys=name,c2,c3,numeric&lang=fr" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Usage Examples

JavaScript/Node.js

// Get all country names
const response = await fetch('/geo/country', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});

const countries = await response.json();
console.log(`Total countries: ${countries.length}`);
// Output: [{ name: "Afghanistan" }, { name: "Albania" }, ...]

// Get countries with ISO codes
const fullResponse = await fetch('/geo/country?keys=name,c2,c3,numeric', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});

const fullCountries = await fullResponse.json();
console.log(fullCountries[0]);
// Output: { name: "Afghanistan", c2: "AF", c3: "AFG", numeric: "004" }

Python

import requests

headers = {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
}

# Get all country names
response = requests.get('https://api.boxapi.com/geo/country', headers=headers)
countries = response.json()
print(f"Total countries: {len(countries)}")

# Get countries with all fields
full_response = requests.get(
    'https://api.boxapi.com/geo/country?keys=name,c2,c3,numeric',
    headers=headers
)
full_countries = full_response.json()
print(full_countries[0])
# Output: {'name': 'Afghanistan', 'c2': 'AF', 'c3': 'AFG', 'numeric': '004'}

PHP

<?php
$apiKey = 'YOUR_API_KEY';

// Get all country names
$ch = curl_init('https://api.boxapi.com/geo/country');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$countries = json_decode($response, true);

echo "Total countries: " . count($countries) . "\n";

// Get countries with all fields
$ch = curl_init('https://api.boxapi.com/geo/country?keys=name,c2,c3,numeric');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$fullCountries = json_decode($response, true);

print_r($fullCountries[0]);
?>

Go

package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

type Country struct {
    Name    string `json:"name"`
    C2      string `json:"c2,omitempty"`
    C3      string `json:"c3,omitempty"`
    Numeric string `json:"numeric,omitempty"`
}

func main() {
    apiKey := "YOUR_API_KEY"

    // Create request
    req, _ := http.NewRequest("GET", "https://api.boxapi.com/geo/country?keys=name,c2,c3,numeric", nil)
    req.Header.Set("Authorization", "Bearer "+apiKey)
    req.Header.Set("Content-Type", "application/json")

    // Send request
    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    // Parse response
    body, _ := io.ReadAll(resp.Body)
    var countries []Country
    json.Unmarshal(body, &countries)

    fmt.Printf("Total countries: %d\n", len(countries))
    fmt.Printf("First country: %+v\n", countries[0])
}

Error Responses

Authentication Error

{
  "error": "Unauthorized"
}

HTTP Status: 401 Unauthorized

Rate Limit Exceeded

{
  "error": "IP blocked",
  "statusCode": 429
}

HTTP Status: 429 Too Many Requests

Internal Server Error

{
  "error": "Internal server error"
}

HTTP Status: 500 Internal Server Error

Rate Limits

The following rate limits apply per IP address:

  • 10,000 requests per minute for successful responses (2xx status codes)
  • 60 requests per minute for client errors (4xx status codes)
  • 60 requests per minute for server errors (5xx status codes)

⚠️ If you exceed these limits, your IP will be temporarily blocked and you'll receive a 429 status code.

Important Notes

  • The endpoint returns 249 countries and territories following ISO 3166-1 standard
  • Invalid field names in the keys parameter are silently ignored
  • If no valid keys are provided, defaults to returning only name field
  • The numeric field is always returned as a 3-digit zero-padded string (e.g., "004", "840")
  • Data is served from in-memory cache for optimal performance
  • Country list follows the official ISO 3166-1 standard maintained by ISO

Common Use Cases

Populating Country Dropdowns

const response = await fetch('/geo/country?keys=name,c2');
const countries = await response.json();

const selectElement = document.getElementById('country-select');
countries.forEach(country => {
    const option = document.createElement('option');
    option.value = country.c2;
    option.textContent = country.name;
    selectElement.appendChild(option);
});

ISO Code Conversion

# Get all countries with codes
response = requests.get(
    'https://api.boxapi.com/geo/country?keys=c2,c3',
    headers={'Authorization': 'Bearer YOUR_API_KEY'}
)
countries = response.json()

# Create lookup dictionaries
c2_to_c3 = {c['c2']: c['c3'] for c in countries}
c3_to_c2 = {c['c3']: c['c2'] for c in countries}

# Convert codes
print(c2_to_c3['US'])  # Output: USA
print(c3_to_c2['GBR'])  # Output: GB

Country Validation

async function isValidCountryCode(code) {
    const response = await fetch('/geo/country?keys=c2');
    const countries = await response.json();
    return countries.some(country => country.c2 === code.toUpperCase());
}

// Usage
const isValid = await isValidCountryCode('US');  // true
const isInvalid = await isValidCountryCode('XX');  // false

Supported Languages

The API supports country name translations in 42 languages:

CodeLanguageCodeLanguageCodeLanguage
amAmharicarArabicbnBengali
deGermanenEnglishesSpanish
faPersianffFulahfrFrench
guGujaratihaHausahiHindi
itItalianjaJapanesejvJavanese
knKannadakoKoreanmlMalayalam
mrMarathimsMalaymyBurmese
omOromoorOdiapaPunjabi
plPolishpsPashtoptPortuguese
roRomanianruRussiansdSindhi
suSundanesetaTamilteTelugu
thThaitlTagalogtrTurkish
ukUkrainianurUrduuzUzbek
viVietnameseyoYorubazhChinese

Language Examples

// Get countries in Spanish
const esResponse = await fetch('/geo/country?lang=es');
const esCountries = await esResponse.json();
console.log(esCountries[0]); // { name: "Afganistán" }

// Get countries in Japanese with codes
const jaResponse = await fetch('/geo/country?keys=name,c2&lang=ja');
const jaCountries = await jaResponse.json();
console.log(jaCountries[0]); // { name: "アフガニスタン", c2: "AF" }

Additional Endpoint

GET /geo/country/info

Get detailed information about the country data endpoint, available fields, and supported languages.

Request:

curl -X GET "https://api.boxapi.com/geo/country/info" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Response:

{
  "description": "This endpoint provides access to a complete list of all countries with their ISO 3166-1 codes...",
  "fields": {
    "c2": "ISO 3166-1 alpha-2 codes (e.g., \"US\", \"GB\")",
    "c3": "ISO 3166-1 alpha-3 codes (e.g., \"USA\", \"GBR\")",
    "numeric": "ISO 3166-1 numeric codes (e.g., \"840\", \"826\")",
    "name": "Country name (localized based on lang parameter)"
  },
  "params": {
    "keys": {
      "type": "string",
      "description": "Comma-separated list of fields to include",
      "default": "name",
      "validValues": ["name", "c2", "c3", "numeric"]
    },
    "lang": {
      "type": "string",
      "description": "Language code for country name translations",
      "default": "en",
      "supportedLanguages": [
        "am", "ar", "bn", "de", "en", "es", "fa", "ff", "fr", "gu",
        "ha", "hi", "it", "ja", "jv", "kn", "ko", "ml", "mr", "ms",
        "my", "om", "or", "pa", "pl", "ps", "pt", "ro", "ru", "sd",
        "su", "ta", "te", "th", "tl", "tr", "uk", "ur", "uz", "vi",
        "yo", "zh"
      ]
    }
  },
  "examples": {
    "Get all countries with names only": "GET /country",
    "Get countries in Spanish": "GET /country?lang=es",
    "Get all countries with all fields": "GET /country?keys=name,c2,c3,numeric"
  }
}

Credit Cost: 1 credit per request