The Instructure Community will enter a read-only state on November 22, 2025 as we prepare to migrate to our new Community platform in early December.
Read our blog post for more info about this change.
Found this content helpful? Log in or sign up to leave a like!
Is there a way of getting the roles available in a course? I don't need all the permissions that each role has, just the roles that are available. You can a list of roles for an account, but most of our users in a course don't have access the account that contains the course and so can't use the account API endpoint (https://canvas.instructure.com/doc/api/roles.html#method.role_overrides.api_index).
What I'm wanting to build is something similar to the roles dropdown that is presented when adding people to a course:
Where do you need that list?
If you're needing it on the People page, then it is contained in the ENV variable with the ALL_ROLES property. However, that's not given on every page, just the ones that need it -- like the roster page.
Another way of getting it is to set up your own service that caches a copy (fetched with a token that has admin permissions) and returns it when requested.
A third option is hard-coding it into the custom JavaScript uploaded through the theme manager. That's a problem if it's changes regularly.
@James Thanks, we are wanting to make an API call on behalf of a user (using a token linked to an API developer key) from an LTI tool.
Our LTI is from launched from the Settings part of a course, but it appears that ENV.ALL_ROLES isn't defined on that page otherwise we could use a bit of custom JS in the theme and window.postMessage() to pass the data across. But thanks for the idea it's really close to working.
We were trying to avoid having an admin token and a server side component that caches the roles as it complicates our setup allow, but maybe that's the way to go 🙁
Hardcoding roles won't fully work as we have some sub-accounts that have custom roles defined in them that aren't defined in other sub-accounts.
Also when you are on the courses page for an account eg: https://instance.instructure.com/accounts/1 there is the JS variable: ENV.COURSE_ROLES which contains all the roles, but again that doesn't help me as I need it in an LTI in the context of a course.
Also looking at the GraphQL endpoint https://canvas.instructure.com/doc/api/file.graphql.html there doesn't seem to be any way to return the roles available in a course there.
Can you use any of the LTI Variable Substitutions? I have an old LTI I wrote that dumps the values of the different variables when called. I do not have it updated for LTI 1.3 and it doesn't seem to return some of the values that are supposed to be returned, so I cannot test myself -- sorry. There are several variables dealing with roles listed there.
From the description, the Canvas.membership.roles sounds the most promising, but the example output is StudentEnrollment rather than the name of the custom roles. It also doesn't say whether it's current membership roles for the current user or in general.
I give this about a <1% chance of success, but I thought I'd mention it just in case.
Thanks @James I had looked at the roles in the variable expansions and it didn't look like any of them would provide anything beyond the roles that the current user has in the course as you say.
We use currently use $Canvas.membership.roles in another tool and it does return the name of the custom roles that the current user has in the course (but not all roles available).
Roles are only available from the Account context, but each course object has an <account_id> and <root_account_id> key you can use to get the appropriate ID number:
course = {
// ...
// the account associated with the course
"account_id": 81259,
// the root account associated with the course
"root_account_id": 81259,
}
Once you have that, you can hit the List Roles endpoint on the root or use the subaccount ID and include inherited values from the parent(s).
Community helpTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in