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
For flag images of countries, check out the Country Flag API instead.
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
/v1/country GET
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.
max_populationoptionalMaximum population of country.
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 in %.
max_infant_mortalityoptionalMaximum infant mortality rate in %.
min_fertilityoptionalMinimum fertility rate in %.
max_fertilityoptionalMaximum fertility rate in %.
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
A JSON array of objects, each containing the following fields, or an error if the request is unsuccessful.
Sample Request Live Demo!
Try our APIs in the API playground
Sign up for a free API key to get started — no credit card required.
https://api.api-ninjas.com/v1/country?name=United%20StatesHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
Code Examples
1
2
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.
/v1/allcountries GETPremium 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
A JSON array of strings, or an error if the request is unsuccessful.
Sample Request
https://api.api-ninjas.com/v1/allcountriesSample Response
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.