URL
GET https://api.country-state-city.rebuscando.info/public/getStates?idcountry={idcountry}
Description
This endpoint retrieves a list of states for a specified country.
Parameters
- idcountry: The numeric identifier of the country for which to retrieve the states (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 state objects.500 Internal Server Error
: An error occurred on the server.
Response Body
The response body is a JSON array of state objects. Each state object contains the following fields:
- _id: Unique identifier for the state in the database (string)
- id: Numeric identifier for the state (integer)
- name: Name of the state (string)
- country_id: Numeric identifier of the country (integer)
- country_name: Name of the country (string)
- country_code: ISO 3166-1 alpha-2 code of the country (string)
- state_code: Code of the state (string)
- latitude: Latitude coordinate of the state (float)
- longitude: Longitude coordinate of the state (float)
- prefix_postalcode: Postal code prefix for the state (string)
Example Response
[
{
"_id": "665d8ff2cba4c7b5eddaafe2",
"id": 5109,
"name": "Albacete",
"country_id": 207,
"country_name": "España",
"country_code": "ES",
"state_code": "AB",
"latitude": 38.9922312,
"longitude": -1.8780989,
"prefix_postalcode": "02"
},
{
"_id": "665d8ff2cba4c7b5eddaafe3",
"id": 5108,
"name": "Alicante",
"country_id": 207,
"country_name": "España",
"country_code": "ES",
"state_code": "A",
"latitude": 38.3579546,
"longitude": -0.5425634,
"prefix_postalcode": "03"
},
{
"_id": "665d8ff2cba4c7b5eddaafe7",
"id": 1189,
"name": "Ávila",
"country_id": 207,
"country_name": "España",
"country_code": "ES",
"state_code": "AV",
"latitude": 40.6934511,
"longitude": -4.8935627,
"prefix_postalcode": "05"
},
{
"_id": "665d8ff2cba4c7b5eddaafe8",
"id": 5092,
"name": "Badajoz",
"country_id": 207,
"country_name": "España",
"country_code": "ES",
"state_code": "BA",
"latitude": 38.8793748,
"longitude": -7.0226983,
"prefix_postalcode": "06"
}...
]
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.