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!
Hi! I am a student messing around with the canvas API using React and seeing all the different things I can access from my classes. I wanted to be able to get the grades and statistics for each of the assignments in my courses, but have been running into "user not authorized to perform that action" errors. I was wondering if there is a workaround to this, or if I am doing something wrong in my code.
Note: I have been using my personal API key to access this information, but have replaced in the code below for privacy. One image is of my server.js file, another is of my main React component. Thank you in advance for any help!
Solved! Go to Solution.
Hi @AtticusMcNulty,
First of all, kudos to you for your experimentation! It's great to see students hacking in the benevolent sense of the term, meaning to learn the capabilities of a system and leverage that knowledge for innovative, unexpected, and beneficial purposes.
The Canvas API will allow the same actions that are available to you through the web interface, and likewise block actions that are not allowed to you through the web interface. The fact that you are getting the "user not authorized" message is evidence of this, and actually means that your code is working.
Out of the box, Canvas has default permissions for each of its five pre-installed roles. These settings are managed by the Canvas administrator for your institution, who may have made some changes from these defaults. (But probably not by much, since the defaults are quite reasonable.)
You'll note that the ability of students to view analytics is turned off by default. This is likely so that, in a small class, you can't determine other students' grades. For instance, if you're in a class of only two students, it would be simple for you to use your analytics view to figure out how your classmate scored on their assignments.
Here are some fun things you can (probably, if you have permission) do with the API:
Have fun and be sure to post back if you have more questions!
Steven Endres (he/him/his)
Director of Learning Technologies
Information Technology (Lewis 001A)
Dominican University | 7900 Division Street | River Forest, IL 60305
Mobile: (708) 466-9452 | sendres@dom.edu | Book a meeting with me
.................................
We are Dominican. We Go First.
Hi @AtticusMcNulty,
Yes, this is something you can do. It's not exactly simple, but the good news is that you can work toward this goal in a step-by-step fashion. If you can get through this process, you will have learned a lot and have a nice project to show a professor or prospective employer demonstrating your knowledge of REST API.
Here's an outline of the steps you'd need to do.
Ready? Get some caffeine, because we'll need it!
Before diving into programming, I recommend becoming familiar with the Canvas API. Here's a simple way to get started.
https://myschool.instructure.com. This is the base URL of your Canvas instance. Copy this address to your clipboard./api/v1/users/self, making the address bar read something like https://myschool.instructure.com/api/v1/users/self. Hit Enter. You should see a JSON response with some basic information about your Canvas user account, formatted in pretty blue, pink, and green colors. If so, you've successfully made a call using your browser to the Canvas API. In this case, because you were logged into Canvas in one tab, your browser included this authorization when it made the API request in another tab, so Canvas was able to allow and respond to the request.Now, we can start writing a program to do get the same information...
First, Canvas will need to see that your program is authorized to request information on your behalf. By far, the easiest way to do this is manually generate an access token.
Second, you can then use your access token to connect to Canvas. Each programming language will have a way to make HTTP requests of different types, with GET, POST, PUT, UPDATE, and DELETE being the most common. You''ll use your language's request function to authenticate to Canvas with your access token and make a request. I recommend making a basic GET request to the same endpoint you used above, /api/v1/users/self, and printing to the screen the JSON data you get back. Once you're able to retrieve your user information, you can move on to something more advanced.
First, from your Dashboard, go visit some of your courses, and note the URLs in your browser address bar. You'll see that each address ends in /courses/<some_number>. These numbers are course ID numbers and are unique to each course.
Now use the API endpoint /api/v1/users/self/courses to get a list of your courses. Try this first in the browser (adding it after your base URL, of course) to see what information you get back. Then modify your program to call this endpoint and produce a list of your courses. There are a few things you'll want to note here:
id parameter that corresponds to the course ID in the address bar when you browse to the course.Once you have a list of your course IDs, you can use these to get a list of assignments in each course using this endpoint: /api/v1/users/self/courses/<course_id>/assignments. These responses will include the following valuable information:
id for each assignment.grading_type, which is typically 'points' but can also be 'pass_fail', 'percent', 'letter_grade', or 'gpa_scale'.points_possible maximum score for the assignment, if the grading_type is points.Onward to the last step...
Finally, you can get the grade for your submission to each assignment using api/v1/courses/<course_id>/assignments/<assignment_id>/submissions/self. These will include the actual grade for the assignment (if one has been assigned).
If you made it this far, you should be very proud of yourself. This is not a trivial project, especially when you're just starting out. Give these steps a try and feel free to ask more questions!
Steven Endres (he/him/his)
Director of Learning Technologies
Information Technology (Lewis 001A)
Dominican University | 7900 Division Street | River Forest, IL 60305
Mobile: (708) 466-9452 | sendres@dom.edu | Book a meeting with me
.................................
We are Dominican. We Go First.
Hi @AtticusMcNulty,
First of all, kudos to you for your experimentation! It's great to see students hacking in the benevolent sense of the term, meaning to learn the capabilities of a system and leverage that knowledge for innovative, unexpected, and beneficial purposes.
The Canvas API will allow the same actions that are available to you through the web interface, and likewise block actions that are not allowed to you through the web interface. The fact that you are getting the "user not authorized" message is evidence of this, and actually means that your code is working.
Out of the box, Canvas has default permissions for each of its five pre-installed roles. These settings are managed by the Canvas administrator for your institution, who may have made some changes from these defaults. (But probably not by much, since the defaults are quite reasonable.)
You'll note that the ability of students to view analytics is turned off by default. This is likely so that, in a small class, you can't determine other students' grades. For instance, if you're in a class of only two students, it would be simple for you to use your analytics view to figure out how your classmate scored on their assignments.
Here are some fun things you can (probably, if you have permission) do with the API:
Have fun and be sure to post back if you have more questions!
Steven Endres (he/him/his)
Director of Learning Technologies
Information Technology (Lewis 001A)
Dominican University | 7900 Division Street | River Forest, IL 60305
Mobile: (708) 466-9452 | sendres@dom.edu | Book a meeting with me
.................................
We are Dominican. We Go First.
Hi! Thank you for the response and all the useful information! I am curious as to if there is a way for me to get the scores of my assignments? Is this something that is possible, or do I need the necessary permissions? If not, is there some workaround?
Thanks again, Atticus
Hi @AtticusMcNulty,
Yes, this is something you can do. It's not exactly simple, but the good news is that you can work toward this goal in a step-by-step fashion. If you can get through this process, you will have learned a lot and have a nice project to show a professor or prospective employer demonstrating your knowledge of REST API.
Here's an outline of the steps you'd need to do.
Ready? Get some caffeine, because we'll need it!
Before diving into programming, I recommend becoming familiar with the Canvas API. Here's a simple way to get started.
https://myschool.instructure.com. This is the base URL of your Canvas instance. Copy this address to your clipboard./api/v1/users/self, making the address bar read something like https://myschool.instructure.com/api/v1/users/self. Hit Enter. You should see a JSON response with some basic information about your Canvas user account, formatted in pretty blue, pink, and green colors. If so, you've successfully made a call using your browser to the Canvas API. In this case, because you were logged into Canvas in one tab, your browser included this authorization when it made the API request in another tab, so Canvas was able to allow and respond to the request.Now, we can start writing a program to do get the same information...
First, Canvas will need to see that your program is authorized to request information on your behalf. By far, the easiest way to do this is manually generate an access token.
Second, you can then use your access token to connect to Canvas. Each programming language will have a way to make HTTP requests of different types, with GET, POST, PUT, UPDATE, and DELETE being the most common. You''ll use your language's request function to authenticate to Canvas with your access token and make a request. I recommend making a basic GET request to the same endpoint you used above, /api/v1/users/self, and printing to the screen the JSON data you get back. Once you're able to retrieve your user information, you can move on to something more advanced.
First, from your Dashboard, go visit some of your courses, and note the URLs in your browser address bar. You'll see that each address ends in /courses/<some_number>. These numbers are course ID numbers and are unique to each course.
Now use the API endpoint /api/v1/users/self/courses to get a list of your courses. Try this first in the browser (adding it after your base URL, of course) to see what information you get back. Then modify your program to call this endpoint and produce a list of your courses. There are a few things you'll want to note here:
id parameter that corresponds to the course ID in the address bar when you browse to the course.Once you have a list of your course IDs, you can use these to get a list of assignments in each course using this endpoint: /api/v1/users/self/courses/<course_id>/assignments. These responses will include the following valuable information:
id for each assignment.grading_type, which is typically 'points' but can also be 'pass_fail', 'percent', 'letter_grade', or 'gpa_scale'.points_possible maximum score for the assignment, if the grading_type is points.Onward to the last step...
Finally, you can get the grade for your submission to each assignment using api/v1/courses/<course_id>/assignments/<assignment_id>/submissions/self. These will include the actual grade for the assignment (if one has been assigned).
If you made it this far, you should be very proud of yourself. This is not a trivial project, especially when you're just starting out. Give these steps a try and feel free to ask more questions!
Steven Endres (he/him/his)
Director of Learning Technologies
Information Technology (Lewis 001A)
Dominican University | 7900 Division Street | River Forest, IL 60305
Mobile: (708) 466-9452 | sendres@dom.edu | Book a meeting with me
.................................
We are Dominican. We Go First.
Great! I got it to work with the instructions you provided. Thank you for all the great information. Another question about using "self", I noticed that if I don't include it I get "unauthorized" errors, presumably as I am a student. Can I add self to other canvas api calls, typically restricted for students, in order to actually be able to call them?
I'll make sure to respond here with further questions (I'm sure I'll have some haha).
Thanks again, Atticus
Hi @AtticusMcNulty,
I'm impressed you got it to work so quickly! Nice job!
When using the API, you'll often need to work with information about a particular user. Just like courses and assignments, each user has a unique ID. When you did the calls to /api/v1/users/self, it returned yours in the id field of the response. Your could put that number in place of "self, as in /api/v1/users/<user_id>, and get the same information. So "self" just a shorthand that refers to "the user ID of the current Canvas user" or "the ID of the person identified in the OAuth token."
As a Canvas admin, I can use "self" to look up my own profile or specify someone else's Canvas ID number to look up their information. As a student you probably can't look up others, so self just makes it convenient to get your info without having to remember your ID.
At least, I don't think you can get (much) information about others. In most courses, you can probably see the People tab, which gives you some information about your classmates. You might experiment with the API to see if you can pull a roster and what information it will share about them. I've never tried these operations with a student account, so I'm curious to know what you find.
Steven Endres (he/him/his)
Director of Learning Technologies
Information Technology (Lewis 001A)
Dominican University | 7900 Division Street | River Forest, IL 60305
Mobile: (708) 466-9452 | sendres@dom.edu | Book a meeting with me
.................................
We are Dominican. We Go First.
Hi Steven,
I hope you're doing well! I have another question regarding the Canvas API. I've recently begun a new term at my university, and I've encountered an issue with some of my new classes. When attempting to retrieve the modules and assignments using the API, I'm receiving "The specified resource does not exist" errors. This is confusing to me because, when I check my actual Canvas page, these same courses indeed have assignments and modules. I know the code is not the issue as I am getting the modules and assignments of other classes just fine. Is this due to a delay in loading new modules/assignments?
Any help is appreciated and let me know if you need any more information.
Thank you in advance, Atticus
Hi @AtticusMcNulty ,
When a resource is created in Canvas, whether through the web interface or the API, it's immediately in the system and available through the API. There's generally no delay in it becoming available for retrieval via the API.
(Full disclosure: there are a very few API endpoints that introduce brief delays. For example, if a teacher uses the API to copy a course—a content migration in Canvas-speak—the new course is created immediately but it takes the system a minute or two to copy all of the assignments, discussions, pages, quizzes, and so on to the new course. For this reason, you can use the Progress API to check the migration and see if it's completed. But I don't think that's at work here because those issues would resolve in minutes and are not relevant to the endpoints you're calling.)
Double check the URL you're fetching. Did you inadvertently leave out the /api/v1 part? I typically see the "specified resource does not exist" when I forget this and am calling the browser URL instead of the API endpoint URL.
If you're building the URL by concatenating strings together, double check for things like using the correct base URL, missing or extra slashes, or similar string formatting errors. If you're adding any parameters at then end of your query, try removing them temporarily to see if a non-parameterized request will work, then add them back in.
I'd also try the request in a browser tab when logged in to Canvas, as we did in Step 3 under "Become Familiar with the Canvas API." I find this is often the fastest way to verify the URL is correct or fix it when it's wrong,
In any case, I'd believe Canvas when it says it can't find the URL you're looking for.
Thank you for the quick response! It took a little while but I found the mistake. I didn't realize up until now that "canvas.instructure.com" (as seen on the api page) should be replaced with "canvas.your_actual_school.edu". Evidently the error was a bit silly, but it is interesting that certain courses were still returning correctly (I made a full working application before realizing). Perhaps you have some insight on that?
Hi @AtticusMcNulty,
I'm glad you figured out the problem, but am completely shocked that your initial program worked while calling canvas.instructure.com.
In my development, I store all the relevant connection details such as the base URL in environment variables on my system. This prevents them from being inadvertently shared with others when I commit code to our repository. Canvas admins also have access to beta and test servers, so loading the base URL from an environment variable makes it easy to switch between servers when necessary.
For these reasons and more, I've never experimented with API calls to canvas.instructure.com and can't provide any insight. Perhaps someone lurking on this thread will be knowledgeable about this issue.
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