Menu

GeoDB Cities API

Getting Cities using multiple filters

You can find cities using a combination of different filters simply by specifying them as parameters in the request.  Currently, the following filters are available:

countryIdsOnly cities in these countries (comma-delimited country codes or wikiDataIds)
excludedCountryIdsOnly cities NOT in these countries (comma-delimited country codes or wikiDataIds)
minPopulationOnly cities having at least this population
namePrefixOnly cities whose names start with this prefix
locationOnly cities near this location. Latitude/longitude in ISO-6709 format: ±DD.DDDD±DDD.DDDD (Note: This param is broken out into separate fields for GraphQL. See GraphQL Schema docs for details.)
timeZoneIdsOnly cities in these time-zones (comma-delimited time-zone IDs). Note that you should use the IDs returned by the GeoDB service, as they correctly encode the '/' character. (Alternatively simply replace '/' with a double-underscore:  '__'.)

Note that some parameters are logically mutually exclusive of each other, and if your request includes them simultaneously, you will quickly be shown the error of your evil ways via a descriptive error response. These are:

  • countryIds, excludedCountryIds  You cannot both include and exclude countries at the same time.
  • location, (countryIds | excludedCountryIds | timeZoneIds)  You cannot include or exclude countries or constrain by time-zones when filtering by location.

Below we find cities starting with 'san', having a minimum population of 100000, and only in the US or Spain.

GraphQL

curl --request POST \
     --url https://geodb-cities-graphql.p.rapidapi.com/ \
     --header 'content-type: application/json' \
     --header 'x-rapidapi-host: geodb-cities-graphql.p.rapidapi.com' \
     --header 'x-rapidapi-key: YOUR_API_KEY' \
     --data '{"query":"QUERY"}'

Where QUERY:

{
  populatedPlaces(namePrefix:"san", countryIds:["US","ES"], minPopulation:100000, first:10) {
    totalCount
    pageInfo{
      startCursor
      endCursor
      hasNextPage
    }
    edges {
      node {
        id
        name
        country {
          name
        }
      }   
    }
  }
}

REST

curl --get --include 'https://wft-geo-db.p.rapidapi.com/v1/geo/cities?namePrefix=san&minPopulation=100000&countryIds=US,ES&offset=0&limit=10' \
    -H 'x-rapidapi-key: YOUR_API_KEY' \
    -H 'x-rapidapi-host: wft-geo-db.p.rapidapi.com'