Black Friday / Cyber Monday Alert: Due to increased traffic demand on mobile communication networks, we are expecting potential congestion for US carrier networks during the Black Friday and Cyber Monday period. Customers may experience intermittent SMS and MMS delivery delays. Please refer to our Black Friday / Cyber Monday FAQ page and our Twilio Status page for more information.

Exporting SMS and Call Logs

First, let’s make sure you are in the right place. Are you looking for raw call and sms logs? Or, are you actually looking for analytics? If you are looking for metrics, reporting, data analysis, etc., please check out our FAQ on doing analytics on Twilio data.

If you’re looking to do a raw export, you’ve come to the right place.

Exporting fewer than 1000 records

To retrieve the last 1000 call records from your logs:

  1. Copy this URL into a text editor:
  2. 'AC12345' is a fake Account SID, so please replace it with your own Account SID
  3. Paste the modified URL from your text editor into the URL bar of your browser and press "Enter"
  4. You'll be prompted for two fields: "Username" and "Password." For "Username," enter your account SID. For "Password," enter your auth token.

Congratulations, you just made a GET request to the Calls list resource! A CSV should now be downloading. You can download your SMS logs by repeating the same process but using this URL instead:

This makes a GET request to the Messages List resource.

Refining this search

The request we just made above asks Twilio to download all calls or messages from your project. But what if you just wanted to look at a subset of these records?

For example, let's say you want to look only at calls to your Twilio number (781) 333-4444, or all messages sent on June 1st, 2012. Twilio supports filters such as "To", "From", "StartTime" (for calls), "DateSent" (for SMS messages), and more. You can append these to your query like this: 

To see all your filtering options for exporting logs, see our Calls list documentation and our Messages list documentation.

Getting lots of data

If you are going to be downloading lots of data from the Twilio API, we highly suggest that you use one of the Twilio CLI or Twilio Helper Libraries to do this.


Twilio CLI Example with Bash

Using a Bash script with the Twilio CLI can be useful if you are looking to quickly create a list of messages with low environment setup. Install the Twilio CLI and log in via the CLI before running the following command:

twilio api:core:messages:list --no-limit --properties="sid,from,to,body,status,direction" \
| while read -r row ; do
echo "$row" >> data.tsv

For the full list of message properties that can be included, see the Twilio Message Resource documentation page.


PHP Code Sample

Here is a simple example of how the PHP Helper Library can be used to download data a CSV of SMS your records. If you find this example timing out, or taking to long, try shortening the time interval of the DateSent filters.

* Download the library from:
* Copy the 'Twilio' folder into a directory containing this file.

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

use Twilio\Rest\Client;

/* Your Twilio account sid and auth token */
$account_sid = "ACXXXXXXXXX";
$auth_token = "YYYYYYYYYYYY";

/* Download data from Twilio API */
$client = new Client($account_sid, $auth_token);
$messages = $client->messages->stream(
  'dateSentAfter' => '2015-05-01',
  'dateSentBefore' => '2015-06-01'

/* Browser magic */
$filename = $account_sid."_sms.csv";
header("Content-Type: application/csv");
header("Content-Disposition: attachment; filename={$filename}");

/* Write headers */
$fields = array( 'SMS Message SID', 'From', 'To', 'Date Sent', 'Status', 'Direction', 'Price', 'Body' );
echo '"'.implode('","', $fields).'"'."\n";

/* Write rows */
foreach ($messages as $sms) {
  $row = array(
    $sms->dateSent->format('Y-m-d H:i:s'),

  echo '"'.implode('","', $row).'"'."\n";

If you prefer not to use the official Helper Libraries, then you're going to need to design your application to make use of the built-in nextpageuri attribute which Twilio's API provides. The nextpageuri is a URL which keeps track of which call or SMS was the last record you fetched and is designed to guide your application through the paging process.

You can use the API Explorer to see examples of the nextpageuri in both XML and JSON.

There isn't a nextpageuri in .CSV format, so if you plan on getting extremely recent records in CSV, you will need to pull the records in either XML or JSON and convert the results to CSV.

Have more questions? Submit a request
Powered by Zendesk