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:
- nameoptional- Name of city. 
- countryoptional- Country filter. Must be an ISO-3166 alpha-2 country code (e.g. - US).
- min_latoptional- Minimum latitude coordinate. 
- max_latoptional- Maximum latitude coordinate. 
- min_lonoptional- Minimum longitude coordinate. 
- max_lonoptional- Maximum longitude coordinate. 
- min_populationoptional- Minimum city population. 
- max_populationoptional- Maximum city population. 
- limitoptional premium- How many results to return. Must be between - 1and- 30. Default is- 1. To get more than 30 results, use the- offsetparameter.
- offsetpremium optional- Number of results to offset for pagination. 
Headers
- X-Api-Keyrequired- API 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.