Welcome to country-state-city microservice

Endpoint: Get Cities

URL

GET https://api.country-state-city.rebuscando.info/public/getCities?idstate={idstate}

Description

This endpoint retrieves a list of cities for a specified state.

Parameters

  • idstate: The numeric identifier of the state for which to retrieve the cities (integer, required).

Response

  • Content-Type: application/json
  • HTTP Status Codes:
    • 200 OK: The request was successful, and the response body contains a JSON array of city objects.
    • 500 Internal Server Error: An error occurred on the server.

Response Body

The response body is a JSON array of city objects. Each city object contains the following fields:

  • _id: Unique identifier for the city in the database (string)
  • id: Numeric identifier for the city (integer)
  • name: Name of the city (string)
  • state_id: Numeric identifier of the state (integer)
  • state_code: Code of the state (string)
  • state_name: Name of the state (string)
  • country_id: Numeric identifier of the country (integer)
  • country_code: ISO 3166-1 alpha-2 code of the country (string)
  • country_name: Name of the country (string)
  • latitude: Latitude coordinate of the city (float)
  • longitude: Longitude coordinate of the city (float)
  • wikiDataId: WikiData identifier for the city (string or null)
  • postalcodes: Array of postal codes for the city (array of strings)

Example Response

[
{
"_id": "665d9053cba4c7b5eddc5fd7",
"id": 152204,
"name": "Albacete",
"state_id": 5109,
"state_code": "AB",
"state_name": "Albacete",
"country_id": 207,
"country_code": "ES",
"country_name": "España",
"latitude": 0.0,
"longitude": 0.0,
"wikiDataId": null,
"postalcodes": [
"02001",
"02002",
"02003",
"02004",
"02005",
"02006",
"02008",
"02049",
"02071",
"02099",
"02140",
"02155",
"02328",
"02511",
"02512"
]
},
{
"_id": "665d9053cba4c7b5eddc5fdb",
"id": 152208,
"name": "Alcalá del Júcar",
"state_id": 5109,
"state_code": "AB",
"state_name": "Albacete",
"country_id": 207,
"country_code": "ES",
"country_name": "España",
"latitude": 0.0,
"longitude": 0.0,
"wikiDataId": null,
"postalcodes": [
"02210",
"02211",
"02214"
]
},
{
"_id": "665d9053cba4c7b5eddc5fdd",
"id": 152210,
"name": "Almansa",
"state_id": 5109,
"state_code": "AB",
"state_name": "Albacete",
"country_id": 207,
"country_code": "ES",
"country_name": "España",
"latitude": 0.0,
"longitude": 0.0,
"wikiDataId": null,
"postalcodes": [
"02640"
]
},
{
"_id": "665d9053cba4c7b5eddc5fe0",
"id": 152213,
"name": "Balazote",
"state_id": 5109,
"state_code": "AB",
"state_name": "Albacete",
"country_id": 207,
"country_code": "ES",
"country_name": "España",
"latitude": 0.0,
"longitude": 0.0,
"wikiDataId": null,
"postalcodes": [
"02320"
]
}...
]

Error Response

If an internal server error occurs, the API will respond with a 500 Internal Server Error status code and an empty response body.