Debugging Twilio - Hangup All Active Calls

If you're an idiot like me you might find yourself using Twilio one day and accidentally making way more phone calls than you intended to. I'm not ashamed to admit that this has now happened to me multiple times. I find myself scrambling for a way to clean up the mess I made, as there is no way to hangup active calls from the Twilio dashboard. Making too many calls too quickly is dangerous because it can use up a lot of Twilio credit very quickly or get your account suspended due to unintentional spam.

Use the following script in case of an emergency. It will hang up every call coming from your account with a status of IN_PROGRESS. You'll need Twilio's Python library installed to run this script. Simply run pip install twilio if you do not already have it.

from twilio.rest import TwilioRestClient
from twilio.rest.resources import Call

ACCOUNT_SID = "YOUR_ACCOUNT_SID"
AUTH_TOKEN = "YOUR_AUTH_TOKEN"
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
calls = client.calls.list(status=Call.IN_PROGRESS)

for c in calls:
    c.hangup()

Note: You may need to replace IN_PROGRESS with QUEUED or RINGING and run the script again.

If you check your Twilio logs and see calls with a status of busy do not worry. These calls have been completed and you are not billed for them.

You can find the Gist for this script here.

If you found this post helpful or would like to give feedback, feel free to reach out to me on Twitter @brodan_.