Created
July 29, 2019 13:56
-
-
Save ttimbers/9ee71b28558f6344d986ec9fcbf12e39 to your computer and use it in GitHub Desktop.
Example of how to get student ID's from Canvas API
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
# assumes instructor's Canvas token is stored as an environmental variable called CANVAS_TOKEN | |
import os | |
import requests | |
canvas_token = os.environ["CANVAS_TOKEN"] | |
resp = requests.get( | |
url=f"https://canvas.ubc.ca/api/v1/courses/19078/enrollments", | |
headers={ | |
"Authorization": f"Bearer {canvas_token}", | |
"Accept": "application/json+canvas-string-ids" | |
}, | |
json={ | |
"enrollment_type": ["student"], | |
"per_page": "100" | |
}, | |
) | |
students = resp.json() | |
student_id = [] | |
for student in students: | |
student_id.append(student['user_id']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment