We have a large account with over a hundred subaccounts. We would like to be able to retrieve all subaccount admin roles for a given user over the API, without having to cycle through every subaccount and list the users. Is this possible? When I go to https://columbiasce.test.instructure.com/api/v1/users/ I don't get any admin information. Thanks!
Solved! Go to Solution.
Sorry about that! I just marked it as none of the answers are correct. Could let us know what question(s) haven't been answered or you're still having problems with?
Sorry for the confusion. After I removed the "Correct" mark from Parsa's original answer, I marked her second answer as Correct.
The answer is that it is currently not possible to retrieve all subaccounts where a user is admin without a separate API query for each subaccount.
This is not an answer to the question, but it is possibly something for consideration.
When I wrote the code for Sorting Dashboard Course Cards , I used the custom user data capability. If someone drags their course cards to a new order, I write that new order to the custom data. Then, when the page loads, I make one API call to look for the existence of that data. If it's there, then I use it to sort the cards -- if not, I don't sort the course cards.
You might be able to work out something similar where you have a separate process that iterates through all of the subaccounts on a regular basis (once a day -- every hour) or on-demand based on your needs and saves whatever information you need to later retrieve for the people that need it. Then, when you need it, you make one API call to check for that variable and obtain all of the information that you previously saved.
Instead of making 100+ calls with every user who is an admin, you make those calls in the background and then make just one call.
Thanks, James! We are currently saving this information in our database, but custom user data is another option, and an intriguing one.
A local database would also work. When I wrote my dashboard sort thing, I was writing something that needed to follow the users around so I couldn't use the browser's storage. That wouldn't work in your case anyway. I also didn't want to have to set up a database on our end to manage all that. Plus, Canvas is generally more reliable than our institution's internet connection and I didn't have to mess with authentication / authorization issues because Canvas already did that.
In the end, using the custom user data made it something that could be shared with people and I've heard that several schools, including some state-wide consortia have adopted it for use.
One thing to watch out for if you used Canvas to hold the data is that the user has access to the information and can change it. Luckily, they still have to have the actual permission in Canvas itself, but someone could lie in the custom data and get the link (or whatever else you're using it for) when they don't really have the permissions to access it.
I would definitely check for the existence of an "admin" role and then make the API call to see what type after they pass that first check.