Created
July 12, 2016 15:43
-
-
Save bryant1410/33789cfb22218da8dcae255caa424fd0 to your computer and use it in GitHub Desktop.
Remove channels from Twilio IP Messaging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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