Search code examples
phpapicanvas-lms

Using the Canvas API to determine if an account belongs to a student or not


I am building an app for my school and I had read a little on Canvas's API and was wondering if anyone on here has played with it.

I am trying to make part of my account validation check whether or not a person is a student (and not a teacher/admin/etc.) but can't find a part of the API to help me with this.

Does anyone have any ideas?


Solution

  • Users in canvas can have multiple roles, that are different based on the context the user is in. For example a user could be a teacher in one course and a student in another. Or a user could be an admin in one account, and not another.

    There are two different endpoints you will need to look at to check what roles a user has.

    Enrollments: https://canvas.instructure.com/doc/api/enrollments.html

    An enrollment object in canvas will tell you what courses a user is in, and their role in the course.

    Admins: https://canvas.instructure.com/doc/api/admins.html#method.admins.index

    The admin endpoint can give you a list of the admins in an account. But you will need an access token that has admin permissions to access this API.