Gerald Q. Maguire

Flexible entry of user identification to a program to use via APIs

Blog Post created by Gerald Q. Maguire on Jul 24, 2020

After the fun yesterday of using the dashboard cards to make the entry of a course ID easier (Using the dashboard information via the API in programs ). I decided to do a similar thing for user IDs, so rather than have to enter a Canvas user_id for each program - why not be more flexible with a "person_id". The result is a program that can take any of several forms of user identification in and get a Canvas user-id for this user. It also shows how to use some of the SIS IDs at Object IDs, SIS IDs, and special IDs - Canvas LMS REST API Documentation.

    # check for numeric string, in which case this a Canvas user_id
    if person_id.isdigit():
    elif person_id.count('-') == 4:     # a sis_integration_id
        integration_id=person_id        # since we have the ID, save it for later
    elif person_id.find('@') > 1:       # if an e-mail address/login ID
        # assume it is a local university ID

    # extract Canvas user-id from the user's info:
    print("sortable name={}".format(info['sortable_name']))
    print("Canvas user_id={}".format(user_id))

    # try to get the user's integration_id via their profile
    integration_id=user_profile.get('integration_id', None)
    login_id=user_profile.get('login_id', None)
    if login_id:

The routines user_info() and user_profile_info() just call the GET /api/v1/users/:id and GET /api/v1/users/:id/profile APIs respectively.


This has some relation to the question I ask in Searching for users and my several iterations of addressing the question.


Also, as noted in my reply to What is the use case for "integration_ids"? in order to get the user's integration_id, i.e., the sis_integration_id) - I had to use the GET /api/v1/courses/:course_id/enrollments API. I'm not completely sure why all of these different IDs for a user are not returned in the User structure returned by GET /api/v1/users/:id .