Overview

Sample Code

Web Hooks

IVR Web Hook SurVo NetGet Custom Audio Prompts Post Call Action Agent Panel Lookup Distributor Form

Call Initiation API

Click-to-Call Click-to-Find Me Click-to-Find Me List Click-to-Virtual Receptionist Click-to-Voice Mail Click-to-SurVo Click-to-IVR Click-to-Agent

Administration API

addonsbroadcastclicktoconferencecostfindmegeneralgrouplocatornumbersrecordingregisterednumbersreportroutingsmssurvoverifymenowvmail

Sample Code

Pull Call Detail Report as XML with PHP/cURL

This example includes many of the most commonly requested columns of the Call Detail Report.


    // Set date format expected by API
    $today = date("Ymd");

    $postData = array(
        'action' => 'report.call_detail',
        'format' => 'xml',
        'access_key' => 'ACCESS_KEY',
        'secret_access_key' => 'SECRET_ACCESS_KEY',
        'start_date' => $today,
        'end_date' => $today,
        'date_added' => 1,
        'ani' => 1,
        'dnis' => 1,
        'phone_label' => 1,
        'call_type' => 1,
        'transfer_type' => 1,
        'transfer_to_number' => 1,
        'sid' => 1,
        'url_tag' => 1,
        'domain' => 1,
        'search_term' => 1,
        'activity_keyword' => 1,
        'custom_value' => 1,
        'custom_id' => 1,
        'ga_client_id' => 1,
        'gclid' => 1,
        'campaign' => 1,
        'platform' => 1,
        'pool_name' => 1,
        'location_name' => 1,
        'sourceguard' => 1,
        'valuetrack' => 1
    );

    // initialize the cURL session, passing in API URL
    $ch = curl_init('https://secure.ifbyphone.com/ibp_api.php');

    // turn on return transfer in cURL session so we can grab the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

    // set cURL to be a POST request
    curl_setopt($ch, CURLOPT_POST, true);

    // Add post values we want to include in the request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    //Execute the session
    $response = curl_exec($ch);

    // Close the cURL session
    curl_close($ch);

    // Load the cURL XML response for parsing
    $xmlData = new DOMDocument();
    $xmlData->strictErrorChecking = false;
    $xmlData->preserveWhiteSpace = false;
    $xmlData->recover = true;
    $xmlData->loadXML($response);
    $records = $xmlData->documentElement;
    $childNodes = $records->childNodes;

    // Loop over each node
    if ($childNodes->length > 0) {
        // Output records
        foreach($records->childNodes as $record) {
            if ($record->hasChildNodes()) {
                $children = $record->childNodes;
                foreach($children as $i) {
                    echo $i->nodeName . ": " . $i->nodeValue;
                }
            }
        }
    } else {
        echo "No Records returned";
    }
    

Sample Listener for webhooks in PHP

This example will allow for logging of any incoming webhook requests.


    /**
    * For this example, the php will live in a file called 'whathappened.php' on your web server
    *
    * Configure any web hook within your account to point at
    * 'http://yourwebserverdomain.com/whathappened.php' to trigger these log entries
    *
    * To look at the log entries from your configured webhook(s), you can access the txt file
    * this script is writing to at: 'http://yourwebserverdomain.com/webhooklog.txt'
    */

    // Place a blank txt file on your web server to receive the log entries
    $file = "webhooklog.txt";

    // Start with blank string on each request
    $whatToLog = '';

    // Incoming GET or POST Request Array
    $request = $_REQUEST;

    foreach($request as $key => $value) {
        // Append each web hook request parameter name and value to string
        $whatToLog .= "$key => $value\n";
    }

    $date = date('c');
    $whatToLog = $date."\r\n".$whatToLog."\r\n\r\n";
    echo $whatToLog;
    file_put_contents($file, $whatToLog, FILE_APPEND);
    

Trigger scheduled broadcast using IVR with PHP/cURL

This example will schedule a "Smart" Broadcast using Click-to-IVR. Set 'survo_id' to the IVR you would like to include in the broadcast.


    // Set to central time
    date_default_timezone_set('America/Chicago');

    // Set date format expected by API
    $startDate = date("Y-m-d H:i", strtotime("+10 minutes"));
    $endDate = date("Y-m-d H:i", strtotime("+20 minutes"));

    // Set the phone number you want to receive the broadcast
    $recipientPhone = '';

    $postData = array(
    'action' => 'clickto.survo',
    'scheduleonly' => 1,
    'access_key' => 'ACCESS_KEY',
    'secret_access_key' => 'SECRET_ACCESS_KEY',
    'survo_id' => 'foo',
    'sdate' => $startDate,
    'edate' => $endDate,
    'tz' => 'Central',
    'type' => 1,
    'phone' => $recipientPhone,
    'dstime' => '00:00',
    'detime' => '23:59'
    );

    // initialize the cURL session, passing in API URL
    $ch = curl_init('https://secure.ifbyphone.com/ibp_api.php');

    // turn on return transfer in cURL session so we can grab the response
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);

    // set cURL to be a POST request
    curl_setopt($ch, CURLOPT_POST, true);

    // Add post values we want to include in the request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    //Execute the session
    $response = curl_exec($ch);

    // Close the cURL session
    curl_close($ch);

    // Load the cURL XML response
    $xml = simplexml_load_string($response);

    // Output Array of response
    print_r($xml);
    

Download call recording with PHP/cURL

This example will download a Call Recording using Recording Download. Set 'sid' to a call that has a recording.


    // API URL
    $url  = 'https://secure.ifbyphone.com/ibp_api.php';

    // Post information for request
    $postData = array(
        'action' => 'recording.download',
        'access_key' => 'ACCESS_KEY',
        'secret_access_key' => 'SECRET_ACCESS_KEY',
        'sid' => 'foo',
        'format' => 'mp3'
    );

    // Start cURL session
    $ch = curl_init($url);

    // set cURL to be a POST request
    curl_setopt($ch, CURLOPT_POST, true);

    // Add post values we want to include in the request
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    // Set cURL to string return value
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Perform Request
    $response = curl_exec($ch);

    // Close Request Session
    curl_close($ch);

    // Check for XML response indicating a problem
    if (!simplexml_load_string($response)) {
        // Download to new file
        $handle = "audiofile.mp3";
        file_put_contents($handle, $response);
        echo "File successfully downloaded";
    } else {
        echo "File download failed" . $response;
    }