Skip to main content

Get a list of Countries

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

export const Highlight = ({children, color}) => ( <span style={{ backgroundColor: color, borderRadius: '2px', color: '#fff', padding: '0.2rem', }}> {children} );

GET https://api.countrystatecity.in/v1/countries

Security

This api use API KEY as an authentication method.

  • Name: X-CSCAPI-KEY
  • In: header

Request Parameters

No parameters

Response

CodeDescription
200Return a list of countries
401Unauthorized.

Example Usage

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)
countries-states-cities.js
var axios = require('axios');

var config = {
method: 'get',
url: 'https://api.countrystatecity.in/v1/countries',
headers: {
'X-CSCAPI-KEY': 'API_KEY'
}
};

axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
countries-states-cities.dart
var headers = {
'X-CSCAPI-KEY': 'API_KEY'
};

var request = http.Request('GET', Uri.parse('https://api.countrystatecity.in/v1/countries'));

request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
print(await response.stream.bytesToString());
} else {
print(response.reasonPhrase);
}
countries-states-cities.js
var settings = {
"url": "https://api.countrystatecity.in/v1/countries",
"method": "GET",
"headers": {
"X-CSCAPI-KEY": "API_KEY"
},
};

$.ajax(settings).done(function (response) {
console.log(response);
});
countries-states-cities.go
url:="https://api.countrystatecity.in/v1/countries"

client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-CSCAPI-KEY", "API_KEY")
res, _ := client.Do(req)
defer res.Body.Close()

bytes ,err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err.Error())
}
fmt.Println(string(bytes))

Example Success Response

[
{
"id": 101,
"name": "India",
"iso2": "IN"
},
...
]

Example Error Response

{
"error'": "Unauthorized. You shouldn't be here."
}