Skip to content

Instantly share code, notes, and snippets.

@bryant1410
Created July 12, 2016 15:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryant1410/33789cfb22218da8dcae255caa424fd0 to your computer and use it in GitHub Desktop.
Save bryant1410/33789cfb22218da8dcae255caa424fd0 to your computer and use it in GitHub Desktop.
Remove channels from Twilio IP Messaging
#!/usr/bin/env python3
import requests
# noinspection SpellCheckingInspection
SERVICE_SID = '...'
# noinspection SpellCheckingInspection
ACCOUNT_SID = '...'
# noinspection SpellCheckingInspection
AUTH_TOKEN = '...'
CHANNELS_ENDPOINT = 'https://ip-messaging.twilio.com/v1/Services/{service_sid}/Channels'.format(service_sid=SERVICE_SID)
list_response = requests.get(CHANNELS_ENDPOINT, params={'PageSize': 1000}, auth=(ACCOUNT_SID, AUTH_TOKEN))
assert list_response.status_code == 200, list_response.reason
assert list_response.json()['meta']['next_page_url'] is None
for channel in list_response.json()['channels']:
if channel['friendly_name'] != 'General Chat Channel':
print("Deleting {name} ({sid})...".format(name=channel['friendly_name'], sid=channel['sid']))
delete_response = requests.delete(
'{endpoint}/{channel_sid}'.format(endpoint=CHANNELS_ENDPOINT, channel_sid=channel['sid']),
auth=(ACCOUNT_SID, AUTH_TOKEN))
assert delete_response.status_code == 204, delete_response.reason
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment