Get a list of Cities within country
Security#
This api use API KEY as an authentication method.
- Name: X-CSCAPI-KEY
- In: header
Request Parameters#
| Name | Located in | Description | Required | Type |
|---|---|---|---|---|
| [ciso] | URL | ISO2 Code of Country | Required | string |
Response#
| Code | Description |
|---|---|
| 200 | Return a list of cities |
| 401 | Unauthorized. |
| 404 | Not Found. |
Example Usage#
- Javascript
- PHP
- Python
countries-states-cities.js
var headers = new Headers();headers.append("X-CSCAPI-KEY", "API_KEY");
var requestOptions = { method: 'GET', headers: headers, redirect: 'follow'};
fetch("https://api.countrystatecity.in/v1/countries/IN/cities", requestOptions).then(response => response.text()).then(result => console.log(result)).catch(error => console.log('error', error));countries-states-cities.php
<?php
$curl = curl_init();
curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.countrystatecity.in/v1/countries/IN/cities', CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array( 'X-CSCAPI-KEY: API_KEY' ),));
$response = curl_exec($curl);
curl_close($curl);echo $response;countries-states-cities.py
import requests
url = "https://api.countrystatecity.in/v1/countries/IN/cities"
headers = { 'X-CSCAPI-KEY': 'API_KEY'}
response = requests.request("GET", url, headers=headers)
print(response.text)Example Success Response#
[ { "id": 133024, "name": "Mumbai", }, ...]Example Error Response#
{ "error'": "Unauthorized. You shouldn't be here."}Example Not Found Response#
{ "error'": "No Cities found."}