PHP code example of voicetel / sdk

1. Go to this page and download the library: Download voicetel/sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

voicetel / sdk example snippets




oiceTel\Sdk\Client;

$client = new Client();

// Exchange username + password for an API key (one-time per session)
$client->login(1000000001, 'hunter2');

// Typed responses — arrays with documented shapes.
$me = $client->account->get();
printf("Balance: \$%.2f  |  Caller ID: %s\n", $me['cash'], $me['callerId']);

// List your numbers
$list = $client->numbers->list();
foreach ($list['numbers'] as $n) {
    printf(
        "%s  route=%d  cnam=%s  sms=%s\n",
        $n['number'],
        $n['route'],
        $n['cnam'] ? 'yes' : 'no',
        $n['smsEnabled'] ? 'yes' : 'no',
    );
}

$client = new Client(apiKey: getenv('VOICETEL_API_KEY'));

$coverage = $client->iNumbering->coverage(['state' => 'NJ']);
foreach ($coverage['coverage'] as $bucket) {
    printf("%s-%s: %d TNs available\n", $bucket['npa'], $bucket['nxx'], $bucket['count']);
}

$client = new Client();
$key = $client->login(1000000001, 'hunter2');
// $key is the new 32-hex bearer; the client already has it installed.

use VoiceTel\Sdk\ApiError;
use VoiceTel\Sdk\ErrorKind;

try {
    $n = $client->numbers->get('9999999999');
} catch (ApiError $e) {
    match ($e->kind) {
        ErrorKind::NotFound  => print "That number isn't on your account.\n",
        ErrorKind::RateLimit => print "Slow down — backoff and retry.\n",
        default              => throw $e,
    };
}

catch (ApiError $e) {
    if ($e->isNotFound())   { /* ... */ }
    if ($e->isRateLimit())  { /* ... */ }
    if ($e->isConflict())   {
        // $e->body is the structured AclConflictData / AuthPutConflictData payload.
    }
}

$client = new Client(
    apiKey: getenv('VOICETEL_API_KEY'),
    maxRetries: 4,
    timeout: 60.0,
);