[ARCHIVED] Pull information through CanvasAPI

Jump to solution
hjs653
Community Novice

So I am assisting a Professor to develop his own personal educational site outside of Canvas.  The Professor I am working with wishes to pull information off of Canvas and display it in the off-site display.  He is wanting to pull general information like the class list and course number, student list, and his students grades.  Is it possible to pull this information from Canvas and push it to his site?

I have read and researched different forums about using Python and the git repository of canvasapi, but I am still deeply confused on how/what I am doing.  Any information would help!

Labels (2)
0 Likes
1 Solution
matthew_emond
Community Participant

Hey  @hjs653 ‌,

I'm one of the lead developers on the CanvasAPI library. It's definitely possible to grab all the information you want with CanvasAPI!

Something like this should be a good starting point:

from canvasapi import Canvas

API_URL = "" # institution base url (e.g. "https://example.instructure.com")
API_KEY = "" # access token

USER_ID = 1 # canvas ID of the user to get course information for

canvas = Canvas(API_URL, API_KEY)

user = canvas.get_user(USER_ID)

courses = user.get_courses()

for course in courses:
print("{} - {} ({})".format(course.course_code, course.name, course.id))
student_enrollments = course.get_enrollments(
type=['StudentEnrollment'],
state=['active']
)
for enrollment in student_enrollments:
print("\t{} {} {}".format(
enrollment.user.get('sortable_name'),
enrollment.grades.get('current_score'),
enrollment.grades.get('current_grade'),
))

Hopefully that gives you some ideas!

The best place to get help with CanvasAPI is to join UCF Open Source on Slack and join the #canvasapi channel. There's lots of friendly folks there willing to help you out! You could also create an issue on our GitHub.

Happy coding,
- Matt Emond

View solution in original post