You need a countries list that matches the country codes used in site traffic analysis, without maintaining the names and codes by hand. By the end of this guide, you can request the list, read it in Python, and use it to label country-level traffic data.
What the countries list contains
Site Traffic API provides a Countries List endpoint that returns the countries supported by its traffic analysis and their codes. Each entry includes a name, two- and three-character codes, a numeric country code, and regional information.
This is useful when a dashboard receives a country code and needs to display a readable name, or when an analytics application needs a selectable list of supported countries. The same API also provides a traffic overview for a domain, including its top five countries, traffic sources, and engagement information.
Getting started on Zyla API Hub
Open the Site Traffic API listing on Zyla API Hub, create an account if needed, and select Subscribe or Start Free Trial when available. Get an API key from your account and use it as a Bearer token in requests to the Hub endpoint.
Zyla uses subscriptions and quotas rather than pay-per-call billing. The first API has a 7-day trial or 50 requests; check the API page for current access options and pricing. The marketplace has more than 10,000 public APIs accessible through one account and API key.
Request the countries list
Countries List is a GET endpoint. Its request does not need a country code or other query parameter; send the authorization header with your key.
https://zylalabs.com/api/29/site-traffic-api/1372/countries-list
curl -s -X GET "https://zylalabs.com/api/29/site-traffic-api/1372/countries-list" \
-H "Authorization: Bearer YOUR_API_KEY"
Replace YOUR_API_KEY with your Hub API key before running the command. The listing shows the following response excerpt; it is truncated, so the excerpt itself is not a complete JSON document.
[{"name":"Afghanistan","alpha-2":"AF","alpha-3":"AFG","country-code":"004","iso_3166-2":"ISO 3166-2:AF","region":"Asia","sub-region":"Southern Asia","intermediate-region":"","region-code":"142","sub-region-code":"034","intermediate-region-code":""},{"name":"Åland Islands","alpha-2":"AX","alpha-3":"ALA","country-code":"248","iso_3166-2":"ISO 3166-2:AX","region":"Europe","sub-region":"Northern Europe","intermediate-region":"","region-code":"150","sub-region-code":"154","intermediate-region-code":""},{"name":"Albania","alpha-2":"AL","alpha-3":"ALB","country-code":"008","iso_3166-2":"ISO 3166-2:AL","region":"Europe","sub-region":"Southern Europe","intermediate-region":"","region-code":"150","sub-region-code":"039","intermediate-region-code":""},{"name":"Algeria","alpha-2":"DZ","alpha-3":"DZA","country-code":"012","iso_3166-2":"ISO 3166-2:DZ","region":"Africa","sub-region":"Northern Africa","intermediate-region":"","region-code":"002","sub-region-code":"015","intermediate-region-code":""},{"name":"American Samoa","alpha-2":"AS","alpha-3":"ASM","country-code":"016","iso_3166-2":"ISO 3166-2:AS","region":"Oceania","sub-region":"Polynesia","intermediate-region":"","region-code":"009","sub-region-code":"061","intermediate-region-code":""},{"name":"Andorra","alpha-2":"AD","alpha-3":"AND","country-code":"020","iso_3166-2":"ISO 3166-2:AD","region":"Europe","sub-region":"Southern Europe","intermediate-region":"","region-code":"150","sub-region-code":"039","intermediate-region-code":""},{"name":"Angola","alpha-2":"AO","alpha-3":"AGO","country-code":"024","iso_3166-2":"ISO 3166-2:AO","region":"Africa","sub-region":"Sub-Saharan Africa","intermediate-region":"Middle Africa","region-code":"002","sub-region-code":"202","intermediate-region-code":"017"},{"name":"Anguilla","alpha-2":"AI","alpha-3":"AIA","country-code":"660","iso_3166-2":"ISO 3166-2:AI","region":"Americas","sub-region":"Latin America and the Caribbean","intermediate-region":"Caribbean","region-code":"019","sub-region-code":"419","intermediate-region-code":"029"},{"name":"Antarctica","alpha-2":"AQ","alpha-3":"ATA","country-code":"010","iso_3166-2":"ISO 3166-2:AQ","region":"","sub-region":"","intermediate-region":"","region-code":"","sub-region-code":"","intermediate-region-code":""},{"name":"Antigua and Barbuda","alpha-2":"AG","alpha-3":"ATG","country-code":"028","iso_3166-2":"ISO 3166-2:AG","region":"Americas","sub-region":"Latin America and the Caribbean","intermediate-region":"Caribbean","region-code":"019","s…
For a country selector, use name as the label and alpha-2 as the stored value. Use alpha-3 or country-code when a downstream system needs those forms. The region fields can support grouping or filtering.
Keep numeric-looking codes as strings. For example, Afghanistan’s country-code is 004; converting it to an integer loses the leading zeros. Also allow for empty region fields: the excerpt shows empty values for Antarctica and empty intermediate-region values for several entries.
Read the list in Python
The following example uses Python’s standard library to call the same endpoint and build a lookup by alpha-2. It prints the name and region for each returned entry. Replace the key before running it, and keep production keys out of source control.
import json
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
url = "https://zylalabs.com/api/29/site-traffic-api/1372/countries-list"
api_key = "YOUR_API_KEY"
request = Request(
url,
headers={"Authorization": f"Bearer {api_key}"},
method="GET",
)
try:
with urlopen(request) as response:
countries = json.load(response)
except HTTPError as exc:
raise SystemExit(f"Countries List request failed: HTTP {exc.code}") from exc
except URLError as exc:
raise SystemExit(f"Could not reach the API: {exc.reason}") from exc
except json.JSONDecodeError as exc:
raise SystemExit("The response was not valid JSON") from exc
if not isinstance(countries, list):
raise SystemExit("Expected a list of countries")
by_alpha2 = {
country["alpha-2"]: country
for country in countries
if isinstance(country, dict) and country.get("alpha-2")
}
for code, country in by_alpha2.items():
name = country.get("name", "")
region = country.get("region", "")
print(f"{code}: {name} ({region})")
The lookup is useful when an application repeatedly resolves codes to names: build it once from a successful response, then reuse it. If a code is missing from the lookup, retain the original code or show an explicit unknown label rather than silently assigning the wrong country.
For a production selector, consider caching the successfully parsed list so every page load does not consume a request. Choose a refresh policy that fits your application, and retain the last successful list if a refresh fails. Check the subscription quota on the listing when deciding how often to refresh.
Use country codes with traffic data
The related Traffic Source and Overview endpoint is a GET request to:
https://zylalabs.com/api/29/site-traffic-api/93/traffic-source-and-overview
It requires the domain parameter. Supply the domain without a URL or www; the documented example uses google.com. The endpoint returns traffic status for the top five countries, sources, and engagement information.
The traffic example includes a TopCountryShares array with Country, CountryCode, and Value fields. To label an entry, look up its CountryCode in the countries list by alpha-2, and handle any code that does not resolve. This keeps the traffic result and the display-name lookup separate.
A reporting dashboard can use the country name for chart labels while retaining the original code for joins. A regional filter can use region or sub-region, but should account for empty values rather than assuming every entry belongs to a populated group.
Call the API from an AI agent
Site Traffic API can also be called through Zyla’s MCP endpoint. Configure an MCP-compatible client, such as Claude Code, Cursor, or Windsurf, with https://mcp.zylalabs.com/mcp?apikey=YOUR_API_KEY, replacing the placeholder with your key.
An agent can use the countries list to resolve supported codes while preparing a traffic report. Treat the key in the MCP URL as a secret: avoid sharing the configured URL or putting it in logs. Check the returned country fields before using them to label traffic data, just as you would in a direct integration.
FAQ
Does the countries list require a query parameter?
No query parameter is needed for the documented Countries List request. Send a GET request with the Bearer authorization header.
Which country code should I store?
For a selector or a lookup against traffic CountryCode values, alpha-2 is a practical starting point. Preserve the other returned codes when another part of your application needs them, and keep numeric-looking codes as strings.
Can I group the results by region?
Yes. Entries contain region, sub-region, and intermediate-region fields, along with corresponding codes. Some values can be empty, so provide an appropriate fallback in your interface.
Does the traffic endpoint return every country?
Traffic Source and Overview describes traffic status for the top five countries. Use Countries List for the supported country reference data; do not treat a single traffic overview as the complete list.
Ready to integrate? Create a free Zyla account, then Start 7-day trial on Site Traffic API when available and get your API key. Check the listing for current access options and pricing before subscribing.