Get a list of Countries
Security#
This api use API KEY as an authentication method.
- Name: X-CSCAPI-KEY
- In: header
Request Parameters#
No parameters
Response#
| Code | Description |
|---|---|
| 200 | Return a list of countries |
| 401 | Unauthorized. |
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", 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', 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"
headers = { 'X-CSCAPI-KEY': 'API_KEY'}
response = requests.request("GET", url, headers=headers)
print(response.text)Example Success Response#
[ { "id": 101, "name": "India", "iso2": "IN" }, ...]Example Error Response#
{ "error'": "Unauthorized. You shouldn't be here."}