Canvas API Error [{'message': 'user not authorized to perform that action'}]

Jump to solution
npadgett
Community Member

Hello All,

I am experiencing the follow error message when using the canvas rest api {'message': 'user not authorized to perform that action'}. Specifically, the endpoint that returns the error sometimes is GET /api/v1/users/:user_id/courses/:course_id/assignments when retrieving assignments for a student. I have narrowed it down to students that are inactive in the course. I still need to get access to assignments that are graded for this student even if they are inactive. Our access token has full permission to all canvas resources so I am confused why I am getting this not authorized error.

Any insight would be extremely helpful. Thank You!

0 Likes
1 Solution
James
Community Champion

npadgett,

This is consistent with the API documentation for List assignments for user (emphasis mine).

Returns the paginated list of assignments for the specified user if the current user has rights to view.

Since the student is inactive, they don't have rights to view it. You need to make the without pretending to be the student.

I use the Submissions API and the List submissions for multiple assignments endpoint. When you specify a student_ids[], it doesn't matter whether the student is inactive or not.

This call fails for an inactive student:

GET /api/v1/users/3346297/courses/896851/assignments

This call suceeds for the same inactive student:

GET /api/v1/courses/896851/students/submissions?student_ids[]=3346297

The second one also gives you the score for the assignment, but not the assignment information itself. If you need information about the assignment, look at the includes[] section of the documentation. You can include[]=assignment to get that information.

You may be able to use GraphQL to get the information. GraphQL is nice for only getting the information that you need to get without all the extra fluff. For example, if you just needed the score, points possible, and assignment name, you could use this query.

query StudentGrades {
course(id: "896851") {
submissionsConnection(studentIds: "3346297") {
edges {
node {
score
assignment {
name
pointsPossible
}
}
}
}
}
}

That request is likely to return all of the grades at once for the student and do it fairly quickly. With the REST API, you are limited to 100 results at a time for the submissions API.

Here's a comparison for my sandbox course and test student shown above.

  • Using the submissions API, the request had an x-request-cost of 0.608 and took about a second to download just the first 100 assignments (yes, my sandbox has more than 100).
  • Using GraphQL, the request had an x-request-cost of 0.125 and took 187 ms to download all of the assignments with grades.

The Submissions API returned assignments that were missing but the graphQL approach did not.


I don't do much with GraphQL, but the Submissions API is the one used by the Canvas gradebook, so that's the one I tend to stick with.

View solution in original post