Sorting API Quiz Submissions By Date

Jump to solution
Tom_R
Community Member

Hi there,

Relatively new to canvas, still learning every day, so sorry if this is a silly question. I am an admin

I am trying to use the Canvas API to return a list of all students (and their grade) who have completed a particular quiz.

For example I started off using this: api/v1/courses/21117/quizzes/135198/submissions  but that only returned 10 results.

I then read about pagination so changed my query to be: api/v1/courses/21117/quizzes/135198/submissions?per_page=100  and that gave me better results and returned roughly 60 students

The problem I have now is the returned data from the above API call is not ordered as I would like it. i.e. a handful of quiz submissions are out of place. Most of the values are in date order, but about 3-4 are scattered in what seems to be a random order.

Is it possible to append a sort by reference to the API call? and have the result sort by quiz date?

Thanks in advance

Labels (1)
0 Likes
1 Solution
James
Community Champion

@Tom_R 

That particular API call does not support sorting the data.

In most API calls, the order returned is determined by the database query, not by an explicit sort order specified by Canvas. This is sometimes the ID of some primary field, but there is no guarantee. You should never rely on the order unless the documentation says it is returned in a specific order, you can specify a sort order in the query, or you've looked at the source code and verified that there is a sort included.

Adding a sort to your code is the best way to handle this when you need the rows in a particular order. The order you want is probably not the order I want, so Canvas frequently leaves that to the end-user to implement.

View solution in original post