/update_communication_channels.py Secret
Created
November 5, 2015 20:52
update_comunication_channels.py takes in a dictionary of HUIDs and email addresses as an input, adds the email address as a communication channel without sending request for confirmation, and prints the communication channels with canvas IDs, etc for each updated profile that can be saved as a tsv file
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
# POST to the Canvas API to add a new communication channel with no notifications sent to the user, August 20, 2015 | |
## Add an access token and a list of HUIDs named id_list | |
import requests | |
import json | |
import csv | |
import operator | |
#from id_email_list import HUID_list_test | |
TOKEN = '' | |
# add an access token | |
#HUID_list = [12345678] | |
# list of HUIDs | |
data = [] | |
# list of data we want from the API call | |
for user_id, email_address in HUID_list_test: | |
# loop over all of the HUIDs in the HUID list | |
url = 'https://canvas.harvard.edu/api/v1/users/sis_user_id:%s/communication_channels' % str(user_id) | |
# call the API and reaise exceptions as needed | |
headers = { | |
'Authorization': 'Bearer {}'.format(TOKEN), | |
} | |
payload = { | |
'communication_channel[address]': email_address, | |
'communication_channel[type]': 'email', | |
'skip_confirmation': '1', | |
} | |
try: | |
resp = requests.post(url, headers = headers, data=payload ) | |
resp.raise_for_status() | |
except requests.exceptions.RequestException as e: | |
print e | |
raise | |
# save json response as a list | |
channels = resp.json() | |
print channels |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment