Manage Your Call Recordings with the REST API


When we talk about our API, sometimes we use the term “REST” without describing what it actually means. When we look under the hood, we find a lots of moving pieces that fit together to make everything work as described.

Realistically, to people who just use Twilio on a day to day basis, those details are not important. The key part developers should understand is “nouns and verbs.”

Four HTTP Verbs Drive REST APIs

The four HTTP verbs that drive REST APIs are POST, GET, PUT, and DELETE. The POST and GET verbs and are well-understood by modern web developers because we use them to create and retrieve our nouns. Less common but just as important is PUT. Ideally, we use it to update our nouns. The fourth verb – DELETE – will delete our noun but is rarely used. Within the Twilio API, we use DELETE in one place: call recordings.

Depending on how you use Twilio, you could easily collect call recordings which you don’t want to store long term. You could delete these via the Dashboard on the site but programmatically using the REST API is more powerful and flexible. It’s even easy if you use our Helper Libraries.

Warning: If you just copy and paste the following code, it will delete all the Recordings within the specified date ranges. Please customize this code before you use it.

In PHP, it’s as simple as authenticating with our Account Sid and AuthToken and then calling the delete method on each Recording. In this sample, I get a specific date range of 50 recordings, display some information, and delete them one by one using their Recording Sid:

Not surprisingly, the equivalent using our Python module is quite similar:

Of course, you can still go with raw cURL from the command line:

* For an updated source of code snippets, please check the official documentation.

Delete Specific Call Recordings

Realistically, we probably don’t want to blindly delete Recordings by date range. We could have important customer calls, voice mail greetings, or other important Recordings. To ensure that the delete focuses exactly on the Recordings we want, we’ll combine a few pieces to make something more useful. In this particular case, first we get a list of Calls filtered by the To phone number and the StartTime. Next, we only delete the call recordings if they are less than 20 seconds. In my account, this To number is used exclusively for testing and development of voice apps, so deleting the shortest call recordings makes sense:

In general, keeping your account “clean” is useful. While everything else within the REST API is text, Recordings are files and large by comparison. If you regularly delete the unimportant files, your processing will be easier and faster.

  • Mike

    Thanks – this was just the information I needed today. You guys are great.  Mike Neighbors, Huntsville, Alabama

  • Mike

    Thanks – this was just the information I needed today. You guys are great.  Mike Neighbors, Huntsville, Alabama

  • TJ Thompson

    Doesn’t seem to work. Put in your dates as shown in the PHP version and it echos out any/every call recording whether in your range or not. We have 150,000 calls to delete.

    Below is the line I adjusted.
    foreach ($client->account->recordings->getIterator(0, 50, array(‘DateCreated>’ => ‘2013-08-01 08:00:00’, ‘DateCreated ‘2013-08-15’)) as $recording)

    First recording being echoed out is most recent and not within my parameters:

    RE5b60cdb7a885e4a953d1571b88db1bdd — Mon, 19 Aug 2013 11:55:04 +0000

    • Keith Casey


      Thanks for the message. It looks like we’ve taken slightly different approaches to get to similar places:

      – You go directly to the Recordings resource to manipulate the list.
      – Alternatively, I go through the Calls resource first and then retrieve the Recordings to manipulate.

      The Calls and Recordings resources take different filter parameters so your example is correct for Recordings while mine is correct for Calls. It’s a subtle difference.

      Also, while your solution takes less API calls to manipulate the recordings, I wanted the additional safety of making sure that I was only deleting recordings that were To a specified number. Regardless, both should work.

      If you run into any other issues or have any questions, don’t hesitate to drop me a note. :)

  • Ivor O’Connor

    You state “Warning: If you just copy and paste the following code, it will delete all the Recordings within the specified date ranges. Please customize this code before you use it.” yet I see no code here to copy and paste.

    I only see two links in the article and they do not reference code. Little help please…

  • alphazebra

    The Credentials.php doc is in the Twilio library, but I don’t see any place to put the Account SID and Token in anywhere. The article just kinda glosses over that. How do I modify that aspect of it?

    • rickyrobinett

      Hi Alphazebra –

      In this case credentials.php is actually a basic php file where you set the variables for your account sid and auth token. Something like this:


      $accountsid = “Your Account Sid”;
      $authtoken = “Your AuthToken”;


      Hope this helps. Don’t hesitate to reach out if you have any other questions.

  • Md Mazedul Islam Khan

    I am getting an Fatal Error. Can anyone please help me about this?

    Fatal error: Uncaught exception ‘Services_Twilio_RestException’ with message ‘Authenticate’ in /home2/root/public_html/delete/twilio-php/Services/Twilio.php:305 Stack trace: #0 /home2/root/public_html/delete/twilio-php/Services/Twilio.php(174): Services_Twilio->_processResponse(Array) #1 /home2/root/public_html/delete/twilio-php/Services/Twilio.php(194): Services_Twilio->_makeIdempotentRequest(Array, ‘/2010-04-01/Acc…’, 1) #2 /home2/root/public_html/delete/twilio-php/Services/Twilio/ListResource.php(125): Services_Twilio->retrieveData(‘/2010-04-01/Acc…’, Array) #3 /home2/root/public_html/delete/twilio-php/Services/Twilio/ListResource.php(200): Services_Twilio_ListResource->getPage(0, 50, Array, NULL) #4 [internal function]: Services_Twilio_ListResource->getPageGenerator(0, 50, Array, NULL) #5 /home2/root/public_html/delete/twilio-php/Services/Twilio/AutoPagingIterator.php(103): call_user_func_array(Array, Array) #6 /home2/root/public_html/delete/twilio-php/Services/Twilio/AutoPagingIterator.php(76): Serv in /home2/root/public_html/delete/twilio-php/Services/Twilio.php on line 305

  • David

    I’m having a Caller leave a message through record verb. i then give the option for the caller to listen to their message through PLAYing the recordingUrl. I then give the Caller the option to press 1 if they are satisfied with the message; or press 2 if they want to re-record.

    Now, if they press 2, meaning they want to re-record, i want to delete the 1st recording. How do I know the sid of the recording that was done in one previous request?

  • mkamoski

    Keith —

    Please help.

    I need to write a utility that uses the Twilio REST API to delete recordings within a given date range.

    However, I need to do it in C#, and I do not know PHP.

    Do you have a C# version of your PHP Delete Recordings Code?

    Please advise.


    — Mark Kamoski