Country API
The Country API provides key geographic, demographic, and economic statistics about every country in the world.
Available endpoints:
- /v1/country - Get country data from given parameters
- /v1/allcountries - Get a list of all countries
Every country result includes flag image URLs (flag_url and flag_square_url). For flags of territories and regions (e.g. England, the EU), check out the Country Flag API.
From 8,067 users
Applications using this API
API Status
API Response Times
Average | P50 | P75 | P90 | P95 |
|---|---|---|---|---|
| 359ms | 386ms | 422ms | 678ms | 1264ms |
Similar APIs
Didn't find what you were looking for? Suggest an improvement
https://api.api-ninjas.com/v1/country
Get country data from given parameters. Returns a list of country statistics that satisfy the parameters.
Parameters
nameoptionalPlain English name, 2-letter ISO-3166 alpha-2, or 3-letter ISO-3166 alpha-3 code of country.
currencyoptional3-letter currency code of country (e.g.
USD).min_gdpoptionalMinimum gross domestic product (GDP) of country, in US Dollars.
max_gdpoptionalMaximum gross domestic product (GDP) of country, in US Dollars.
min_populationoptionalMinimum population of country (in thousands).
max_populationoptionalMaximum population of country (in thousands).
min_areaoptionalMinimum surface area of country in km2.
max_areaoptionalMaximum surface area of country in km2.
min_unemploymentoptionalMinimum unemployment rate in %.
max_unemploymentoptionalMaximum unemployment rate in %.
min_gdp_growthoptionalMinimum GDP growth rate in %.
max_gdp_growthoptionalMaximum GDP growth rate in %.
min_infant_mortalityoptionalMinimum infant mortality rate per 1,000 live births.
max_infant_mortalityoptionalMaximum infant mortality rate per 1,000 live births.
min_fertilityoptionalMinimum fertility rate (average number of children per woman).
max_fertilityoptionalMaximum fertility rate (average number of children per woman).
min_urban_pop_rateoptionalMinimum urban population rate in %.
max_urban_pop_rateoptionalMaximum urban population rate in %.
limitoptionalHow many results to return. Must be between
1and30. Default is5.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
The /v1/country endpoint returns a JSON array of objects, each with the following fields, or an error if the request is unsuccessful.
nameCountry name
iso22-letter ISO-3166 alpha-2 country code
gdpGross domestic product (GDP) in millions of US Dollars
gdp_growthGDP growth rate in %
gdp_per_capitaGDP per capita in US Dollars
populationTotal population (in thousands)
pop_growthPopulation growth rate in %
pop_densityPopulation density per km²
currencyCurrency object with code (3-letter currency code) and name
capitalCapital city
regionGeographic region
surface_areaSurface area in km²
unemploymentUnemployment rate in %
employment_agricultureEmployment in agriculture sector in %
employment_industryEmployment in industry sector in %
employment_servicesEmployment in services sector in %
life_expectancy_maleLife expectancy for males in years
life_expectancy_femaleLife expectancy for females in years
infant_mortalityInfant mortality rate per 1000 live births
fertilityFertility rate (average number of children per woman)
sex_ratioSex ratio (males per 100 females)
urban_populationUrban population as % of total population
urban_population_growthUrban population growth rate in %
primary_school_enrollment_malePrimary school enrollment rate for males in %
primary_school_enrollment_femalePrimary school enrollment rate for females in %
secondary_school_enrollment_maleSecondary school enrollment rate for males in %
secondary_school_enrollment_femaleSecondary school enrollment rate for females in %
post_secondary_enrollment_malePost-secondary school enrollment rate for males in %
post_secondary_enrollment_femalePost-secondary school enrollment rate for females in %
importsImports in millions of US Dollars
exportsExports in millions of US Dollars
co2_emissionsCO2 emissions in millions of metric tons
forested_areaForested area as % of total land area
threatened_speciesNumber of threatened species
homicide_rateHomicide rate per 100,000 people
touristsNumber of tourists (in thousands)
refugeesNumber of refugees (in thousands)
internet_usersInternet users as % of total population
telephone_country_codesArray of telephone country codes
flag_urlURL to the country's flag image (4:3 rectangle, SVG)
flag_square_urlURL to the country's flag image (1:1 square, SVG)
Live Demo
Get a free API key to get started — no credit card required.
Code Examples
curl -X GET "https://api.api-ninjas.com/v1/country?name=United%20States" \
-H "X-Api-Key: YOUR_API_KEY"If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.
Premium only
https://api.api-ninjas.com/v1/allcountries
Get a list of all 2-letter country codes for countries, territories and regions for which we have statistics.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Response
The /v1/allcountries endpoint returns a JSON array of strings, or an error if the request is unsuccessful.
Live Demo
Get a free API key to get started — no credit card required.
Code Examples
curl -X GET "https://api.api-ninjas.com/v1/allcountries" \
-H "X-Api-Key: YOUR_API_KEY"Frequently Asked Questions
Can I use the Country API for commercial purposes?
Yes, but you must have a premium subscription. Commercial use of the Country API is not permitted on the free tier. See our pricing page to choose a plan that fits your needs.How do I get an API key and start using the Country API?
Sign up for a free account to instantly get your API key, then pass it in theX-Api-Keyheader on every request. The documentation above includes ready-to-run examples in cURL, Python, JavaScript, Node.js, and more.What happens if I exceed my quota for the month?
Your API requests will simply be denied once you hit your monthly quota — you will never be charged more than the plan you signed up for. To increase your quota, you can upgrade your plan any time on our pricing page.What happens if a request to the Country API fails?
The API responds with a standard HTTP status code and a JSON error message describing the problem. See our error codes reference for the full list of codes and how to resolve each one, or contact support if you need help.What statistics does the Country API return for each country?
Each result is a JSON object packed with geographic, demographic, and economic indicators includinggdp,gdp_per_capita,population,pop_density,capital,currency,life_expectancy_male,unemployment,co2_emissions, andinternet_users, among many others. For a country's flag image use the Country Flag API, and for deeper population or GDP figures see the Population API and GDP API.How do I look up a specific country with the /v1/country endpoint?
Pass thenameparameter, which accepts a plain English name, a 2-letter ISO-3166 alpha-2 code, or a 3-letter ISO-3166 alpha-3 code (for examplename=United Statesorname=US). For city-level lookups instead, check out the City API.Can I filter or search for countries by their statistics?
Yes, the /v1/country endpoint supports filter parameters such ascurrency,min_population,max_population,min_gdp,max_gdp,min_unemployment, andmin_fertility, and you can cap the number of matches with thelimitparameter (between1and30, default5). See our APIs for related data sources you can combine with these results.What is the /v1/allcountries endpoint and how does it differ from /v1/country?
The premium-only /v1/allcountries endpoint returns a JSON array of every 2-letter country code for the countries, territories, and regions we cover, whereas /v1/country returns full statistics objects for countries matching your parameters. Upgrade details are on our pricing page.
Explore API integration use cases for recommended APIs and workflow examples.