PHP Quickstart: Call Record Retrieval

Call logs from REST

The last component of this quickstart is retrieving your call logs using the Twilio REST API. You can find your logs by going to the the Logs page of your account on the Twilio web site, but getting access to this data programmatically is useful for automated reporting, or building other fully-featured systems like a voicemail application.

To get a list of recent calls, perform an HTTP GET to the Calls resource URI.

    // Include the Twilio PHP library
    require 'Services/Twilio.php';

    // Twilio REST API version
    $version = '2010-04-01';

    // Set our AccountSid and AuthToken
    $sid = 'AC123';
    $token = 'abcd';

    // Instantiate a new Twilio Rest Client
    $client = new Services_Twilio($sid, $token, $version);

    try {
        // Get Recent Calls
        foreach ($client->account->calls as $call) {
            echo "Call from $call->from to $call->to at $call->start_time of length $call->duration";
    } catch (Exception $e) {
        echo 'Error: ' . $e->getMessage();
  • We create a client object and perform an HTTP GET request to the Calls resource.
  • If no errors occur, we print out a list of the Call records.

Then run the script to retrieve your list of calls:

$ php call-log.php

For more information check out the Twilio REST API documentation. If you have questions, comments, or suggestions about this quickstart, then give us a howl in the forums.

Next: Turn your browser into a phone with Twilio Client »