cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Surveyor

Getting 401 when accessing API

Jump to solution

I'm a staff member at an institution that's comprised of three schools. I'm trying to write a simple python script to retrieve the current grades for a select group of students to save myself and others the time of doing it manually through the web application. My account has admin privileges for the sub account that holds the students I need the grades for but it does not have admin privileges for the main account that holds the sub account for the three schools. I've generated an access token from my settings area on the web app but when I try using it to access data through the live API, I get a 401. This is puzzling since I can access this exact data manually through the web app. I brought my problem to the top admin and when he generated an access token with his account, it worked fine. I've searched around for someone who's had the same problem as me but haven't come up with anything. Please let me know if you have any idea what the issue could be. Any help would be very much appreciated!

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Surveyor

Thanks very much for your replies everyone. Since I can't access the user data directly, I eventually settled on grabbing the enrollments through the course objects. Works well but involves manually grabbing each student's course numbers at the start of the semester and storing them in a csv file. I may eventually do the latter part programmatically but am satisfied with it as is.

Thanks again!

View solution in original post

10 Replies
Highlighted
Surveyor II

What is the api endpoint you are trying to access? I know there are some that you need root access for. You also get a 401 if you`re trying to access an account that doesn't exists, but as you`ve stated your root account admin can access the resource so that should not be the issue.

Highlighted
Surveyor

btb,

If you're using python and if you're already not using canvasapi, I recommend you install it.

https://github.com/ucfopen/canvasapi

This will massively reduce pain points and help you achieve your goals without having to worry about various API endpoints.

 

Highlighted

Thanks for the response! I've been trying to access /v1/users/{user_id}/enrollments. Is there a list somewhere that details which endpoints require root access?

Highlighted
Surveyor II

It sounds like all your users are in your root account. This would explain why you don`t have access to /users. I don't have a list of endpoints, but this one seems fairly clear to me from what you described.

Highlighted

Yeah I believe they are. Do you know if there's any way I can get permission to access the student data without being made a root admin? Is there somewhere I can read up on why I can access those students in the web app but not through the API?

Highlighted
Explorer III

One of the elegant things about the API is that it precisely aligns with your permissions, so you should be able to access things in the API that you can in the GUI.

If you're familiar with your browser developer tools, you can see XHR requests to the API all the time in the Network panel. It's one way to get a sense of how it works.

Highlighted
Explorer III

p.s. have you played with your /doc/api/live page?

Highlighted

There is a document that I use when trying to determine what access needs to be given when a new token is requested:

https://s3.amazonaws.com/tr-learncanvas/docs/Canvas_Permissions_Account.pdf

Highlighted

As dtod mentioned, you have access to all resources that you can access through the GUI. This means you can see everything within your subaccount. Since they could have results outside of your subaccount, you will not be able to access all their grades directly through the api on a user level.

You can however get access to all the results for courses within your subaccount. It will be a lot harder to get this information since you will have to scrape all courses within your subaccount to find out their enrollments and then get the results for those courses.

 

As for documentation, have a look at this page: https://community.canvaslms.com/t5/Developers-Group/Canvas-APIs-Getting-started-the-practical-ins-an...