City API
The City API provides useful statistics about tens of thousands of cities around the world.
| Plan | Available Cities |
|---|---|
| Free | ~50,000 cities |
| Premium | More than 5,000,000 cities, towns, and villages |
/v1/city GET
https://api.api-ninjas.com/v1/city
Get city data from either a name or population range. Returns a list of cities that satisfies the parameters.
Parameters
At least one of the following parameters (other than limit and offset) must be set:
nameoptionalName of city.
countryoptionalCountry filter. Must be an ISO-3166 alpha-2 country code (e.g.
US).min_latoptionalMinimum latitude coordinate.
max_latoptionalMaximum latitude coordinate.
min_lonoptionalMinimum longitude coordinate.
max_lonoptionalMaximum longitude coordinate.
min_populationoptionalMinimum city population.
max_populationoptionalMaximum city population.
limitoptional premiumHow many results to return. Must be between
1and30. Default is1. To get more than 30 results, use theoffsetparameter.offsetpremium optionalNumber of results to offset for pagination.
Headers
X-Api-KeyrequiredAPI Key associated with your account.
Sample Request Live Demo!
https://api.api-ninjas.com/v1/city?name=San FranciscoHeaders
X-Api-KeyLog in or sign up to get your API KeySample Response
1
2
3
4
5
6
7
8
9
10
[
{
"name": "San Francisco",
"latitude": 37.7562,
"longitude": -122.443,
"country": "US",
"population": 3592294,
"is_capital": false
}
]Code Examples
1
2
curl -X GET "https://api.api-ninjas.com/v1/city?name=London" \
-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.