Skip to main content

Get List of All Countries

You can retrieve a list of all available countries by making a GET request to the following endpoint:

GET https://api.veritel.io/countries?token=$token

Parameters

FieldTypeRequiredDescription
tokenStringyesYour API key

Result

A successful request will return a JSON array of country objects:

{
"success": true,
"response": [
{"id": 0, "title": "Russia"},
{"id": 3, "title": "China"}
]
}

Possible Errors

If the request fails, you will receive an error response:

{
"success": false,
"error_code": "wrong_token",
"error_msg": "Wrong token!"
}

Example Code

Below is an example of how to get the list of all countries using modern JavaScript (Fetch API):

async function getCountries(apiUrl, token) {
try {
const url = new URL(`${apiUrl}/countries`);
url.searchParams.append('token', token);

const response = await fetch(url.toString(), {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});

if (response.ok) {
const data = await response.json();
console.log('Countries List:', data.response);
return data.response;
} else {
const errorData = await response.json();
throw new Error(`Error: ${errorData.error_msg}`);
}
} catch (error) {
console.error('Error:', error.message);
throw error;
}
}

// Example usage
const apiUrl = 'https://api.veritel.io';
const token = 'your_api_key_here';

getCountries(apiUrl, token)
.then(data => console.log('List of countries:', data))
.catch(error => console.error('Failed to retrieve countries list:', error.message));

Security

  • API Key: Ensure you use your correct API key when making requests.

Responses

  • 200 OK: The request was successful. Example response:
    {
    "success": true,
    "response": [
    {"id": 0, "title": "Russia"},
    {"id": 3, "title": "China"}
    ]
    }
  • Error Response: Example response for an incorrect token:
    {
    "success": false,
    "error_code": "wrong_token",
    "error_msg": "Wrong token!"
    }