Objective
If you're looking to bulk delete your Twilio recordings, this guide will walk you through the necessary steps. We understand that managing a large number of recordings can be challenging, and we're here to help make the process as smooth as possible.
Product
Programmable Voice
Environment
legacy Twilio Console
Procedure
Important Considerations
Before proceeding with any deletion, it's crucial to understand the following:
- Individual Deletion: The Twilio API does not support a single call to delete all recordings at once. Each recording must be deleted individually, either via the Twilio Console's bulk UI or through a series of API calls.
- Irreversibility: Once a recording is deleted, it cannot be recovered. Please ensure you have a backup or are certain you no longer need the recordings before you delete them.
- Potential Errors: You may encounter an error (e.g., Error 16110) when processing bulk deletion requests through the Twilio Console due to an internal failure.
Solution: Using a Script for Deletion
For large datasets, using a script is the most efficient and reliable method to handle the deletion process. Below is a sample Node.js script that demonstrates how to delete recordings with optional filters.
Prerequisites
You need the Twilio helper library for Node.js. Install it using npm:
npm install twilio
Sample Script
The following script uses an asynchronous approach to fetch and delete recordings based on specified criteria. Once you have written the appropriate filter, uncomment the line in the script.
// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
const accountSid = '';
const authToken = '';
const client = require('twilio')(accountSid, authToken);
// Delete single recording
async function deleteRecording(sid) {
// await client.recordings(sid).remove(); // uncomment when ready
console.log(`Deleted: ${sid}`);
}
// Delete all recordings with filter options
async function deleteRecordingsWithFilter(options = {}) {
try {
// Get recordings with optional filters
const recordings = await client.recordings.list(options);
console.log(`Found ${recordings.length} recordings matching filter criteria...`);
if (recordings.length === 0) {
console.log('No recordings found matching the criteria.');
return;
}
// Delete each recording
const deletePromises = recordings.map(recording =>
deleteRecording(recording.sid)
);
await Promise.all(deletePromises);
console.log(`Successfully deleted ${recordings.length} filtered recordings!`);
} catch (error) {
console.error('Error deleting filtered recordings:', error);
throw error;
}
}
// Run the deletion with filter options
deleteRecordingsWithFilter({
dateCreatedBefore: new Date('2024-01-01')
});
Filtering Options
You can customize the script by providing different filter options to the deleteRecordingsWithFilter function. For a full list of available query parameters, refer to the Twilio Recording API documentation. Common filters include dateCreatedBefore, callSid, and conferenceSid.
Additional Information
While bulk deleting voice recordings can present challenges, using a script provides a robust and reliable solution. By understanding the limitations of the API and leveraging a programmatic approach, you can efficiently manage and remove your Twilio recordings, ensuring a smoother and more controlled process.