Outbound Call API - PHP SDK/Helper library

Voice2Phone Server-side SDKs

Server-side SDKs make it easy for you to use Voice2Phone's Outbound Phone Calling REST APIs. These helper libraries are available in a variety of popular server-side programming languages.

PHP Helper Library

The Voice2Phone PHP SDK makes it easy to interact with the Voice2Phone Outbound Phone Calling API from your PHP application. The most recent version of the Voice2Phone PHP SDK can be found on Packagist. The Voice2Phone SDK requires PHP version 5.3 or higher.

Using with Composer

The recommended method for installing the SDK is via Composer. You can add the PHP SDK to your composer.json file with the require command.

composer require voice2phone/voice2phone-php-client

If you're using Composer in an environment that doesn't handle autoloading, you can require the autoload file from the "vendor" directory created by Composer if you used the install command above. Here is a basic example of using the SDK to make a phone call:


require __DIR__ . '/vendor/autoload.php';

$apiSercretKey = "Your API Secret Key";
$phone = "Your Phone Number";
$countryCode = "Your TWO letter country code;
$message = "Hello, Please press one or two";


$res = Voice2Phone\RestClient::MakeCall($apiSercretKey, 
        $phone, 
        $countryCode, 
        $message,  
        array("1"=>"You pressed one", "2"=>"You pressed two") );

print "Http Status: " . $res->HttpStatus;
print "Error: " . $res->ErrorMessage;
if ($res->HttpStatus == 200)
{
    print "Call Id: " . $status->CallId;
    $status = Voice2Phone\RestClient::GetCallStatus($apiSercretKey, $res->CallId);
    print "Status: " . $status->Status;
    print "CreatedDateUtc: " . $status->CreatedDateUtc;
    print "UpdatedDateUtc: " . $status->UpdatedDateUtc;
    print "Dtmf: " . $status->Dtmf;
}

Using without Composer

While we recommend using a package manager to track the dependencies in your application, it is possible to download and use the PHP SDK manually. You can download the full source of the PHP SDK from GitHub, and browse the repo if you would like. To use the SDK in your application, unzip the SDK download file in the same directory as your PHP code. In your code, you can then require the autoload file bundled with the SDK.

use Voice2Phone;
include 'voice2phone.php';

$apiSercretKey = "Your API Secret Key";
$phone = "Your Phone Number";
$countryCode = "Your TWO letter country code;
$message = "Hello, Please press one or two";


$res = Voice2Phone\RestClient::MakeCall($apiSercretKey, 
        $phone, 
        $countryCode, 
        $message,  
        array("1"=>"You pressed one", "2"=>"You pressed two") );

print "Http Status: " . $res->HttpStatus;
print "Error: " . $res->ErrorMessage;

if ($res->HttpStatus == 200)
{
    print "Call Id: " . $status->CallId;
    $status = Voice2Phone\RestClient::GetCallStatus($apiSercretKey, $res->CallId);
    print "Status: " . $status->Status;
    print "CreatedDateUtc: " . $status->CreatedDateUtc;
    print "UpdatedDateUtc: " . $status->UpdatedDateUtc;
    print "Dtmf: " . $status->Dtmf;
}

Getting Help

We'd love to hear your feedback on the PHP SDK, and help you past any issues you may encounter. Feel free to drop us a line, and we'll make sure to get you sorted!