Skip to main content

Get the state details from ISO2 code or ID

GET http://api.countrystatecity.org/v1/countries/{cisoORid}/states/{sisoORid}

Authentication#

This free api uses API Key to authenticate. API Key needs to be passed in headers.

  • Header Name : X-API-KEY

Request Parameters#

NameLocationDescriptionRequiredType
{cisoORid}URLISO2 Code OR IDYESstring
{sisoORid}URLISO2 Code OR IDYESstring

Response#

CodeDescription
200Returns a state detail
401Unauthorized
404Not Found

Example Usage#

script.js
var headers = new Headers();
headers.append("X-API-KEY", "api key value");
var requestOptions = {
method: 'GET',
headers: headers,
redirect: 'follow'
};
fetch("https://api.countrystatecity.org/v1/countries/IN/states/MH", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

Example Success Response#

Success Response
[
{
"id": 4008,
"name": "Maharashtra",
"country_id": 101,
"country_code": "IN",
"iso2": "MH"
},
...
]

Example Error Response#

Error Response
{
"error":"Unauthorized. Please provide X-API-KEY and api key value in header."
}

Example NotFound Response#

Error Response
{
"error":"No state found."
}