Skip to content

Instantly share code, notes, and snippets.

@GlitchWitch
Last active March 13, 2021 03:17
Show Gist options
  • Save GlitchWitch/6a72ef0fc3e7c9f4f3e82ca2a2de0363 to your computer and use it in GitHub Desktop.
Save GlitchWitch/6a72ef0fc3e7c9f4f3e82ca2a2de0363 to your computer and use it in GitHub Desktop.
Bash scripts for deleting all Voicemails, Call Logs, and Messages from your Twilio account.
#!/bin/sh
# Delete all call logs from your Twilio account
#
# Requires:
# * curl - transfer a URL
# * jq - Command-line JSON processor
#
cd "$(dirname "$0")"
accountSID='ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # REQUIRED
authToken='TWILIO_AUTH_TOKEN' # REQUIRED
test -f ./auth.sh && . ./auth.sh
if test -z "$accountSID" -o -z "$authToken"
then
cat <<EOF >&2
accountSID and authToken must be set at the top of this script
or in a file called auth.sh in the same directory as this script.
They can be found in your Twilio dashboard:
https://www.twilio.com/console
EOF
exit 1
fi
if test -z "$(which curl)" -o -z "$(which jq)"
then
cat <<EOF >&2
curl and jq are required.
curl: https://curl.haxx.se/
jq: https://stedolan.github.io/jq/
EOF
exit 2
fi
api="https://api.twilio.com/2010-04-01/Accounts/$accountSID"
auth="$accountSID:$authToken"
curl "$api/Calls.json" -u "$auth" -s |
jq '.calls[] | .sid' --raw-output |
while read -r callSID
do
echo "Delete Call $callSID..."
curl -X DELETE "$api/Calls/$callSID.json" -u "$auth" -s
done
echo 'Done.'
#!/bin/sh
# Delete all message logs from your Twilio account
#
# Requires:
# * curl - transfer a URL
# * jq - Command-line JSON processor
#
cd "$(dirname "$0")"
accountSID='ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # REQUIRED
authToken='TWILIO_AUTH_TOKEN' # REQUIRED
test -f ./auth.sh && . ./auth.sh
if test -z "$accountSID" -o -z "$authToken"
then
cat <<EOF >&2
accountSID and authToken must be set at the top of this script
or in a file called auth.sh in the same directory as this script.
They can be found in your Twilio dashboard:
https://www.twilio.com/console
EOF
exit 1
fi
if test -z "$(which curl)" -o -z "$(which jq)"
then
cat <<EOF >&2
curl and jq are required.
curl: https://curl.haxx.se/
jq: https://stedolan.github.io/jq/
EOF
exit 2
fi
api="https://api.twilio.com/2010-04-01/Accounts/$accountSID"
auth="$accountSID:$authToken"
curl "$api/Messages.json" -u "$auth" -s |
jq '.messages[] | .sid' --raw-output |
while read -r messageSID
do
echo "Delete Message $messageSID..."
curl -X DELETE "$api/Messages/$messageSID.json" -u "$auth" -s
done
echo 'Done.'
#!/bin/sh
# Delete all voicemail recordings from your Twilio account
#
# Requires:
# * curl - transfer a URL
# * jq - Command-line JSON processor
#
cd "$(dirname "$0")"
accountSID='ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # REQUIRED
authToken='TWILIO_AUTH_TOKEN' # REQUIRED
test -f ./auth.sh && . ./auth.sh
if test -z "$accountSID" -o -z "$authToken"
then
cat <<EOF >&2
accountSID and authToken must be set at the top of this script
or in a file called auth.sh in the same directory as this script.
They can be found in your Twilio dashboard:
https://www.twilio.com/console
EOF
exit 1
fi
if test -z "$(which curl)" -o -z "$(which jq)"
then
cat <<EOF >&2
curl and jq are required.
curl: https://curl.haxx.se/
jq: https://stedolan.github.io/jq/
EOF
exit 2
fi
api="https://api.twilio.com/2010-04-01/Accounts/$accountSID"
auth="$accountSID:$authToken"
curl "$api/Recordings.json" -u "$auth" -s |
jq '.recordings[] | .sid' --raw-output |
while read -r recordingSID
do
echo "Delete recording $recordingSID..."
curl -X DELETE "$api/Recordings/$recordingSID.json" -u "$auth" -s
done
echo 'Done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment