Request a Phone Number
You can request a phone number by making a GET request to the following endpoint:
GET https://api.veritel.io/get-number?token=$token&country_id=$country_id&service_id=$service_id
Parameters
| Field | Type | Required | Description |
|---|---|---|---|
| token | String | yes | Your API key |
| country_id | Integer | yes | Number country ID |
| service_id | Integer | yes | Number service ID |
Result
A successful request will return a JSON object with the requested phone number details:
{
"success": true,
"response": {
"operation_id": 124,
"country_id": 44,
"service_id": 4,
"number": "+447518396720"
}
}
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 request a phone number using modern JavaScript (Fetch API):
async function requestPhoneNumber(apiUrl, token, countryId, serviceId) {
try {
const url = new URL(`${apiUrl}/get-number`);
url.searchParams.append('token', token);
url.searchParams.append('country_id', countryId);
url.searchParams.append('service_id', serviceId);
const response = await fetch(url.toString(), {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
if (response.ok) {
const data = await response.json();
console.log('Phone Number Request:', 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';
const countryId = 44; // Required
const serviceId = 15; // Required
requestPhoneNumber(apiUrl, token, countryId, serviceId)
.then(data => console.log('Requested phone number details:', data))
.catch(error => console.error('Failed to request phone number:', 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": {
"operation_id": 2452,
"country_id": 44,
"service_id": 15,
"number": "+447438713073"
}
} - Error Response: Example response for an incorrect token:
{
"success": false,
"error_code": "wrong_token",
"error_msg": "Wrong token!"
}