Skip to content

Instantly share code, notes, and snippets.

@ttimbers
Created July 29, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttimbers/9ee71b28558f6344d986ec9fcbf12e39 to your computer and use it in GitHub Desktop.
Save ttimbers/9ee71b28558f6344d986ec9fcbf12e39 to your computer and use it in GitHub Desktop.
Example of how to get student ID's from Canvas API
# 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