Courses API request doesn't return all courses

Jump to solution
WHusen
Community Member

Hey there,

I'm a student working on automating a calendar of my assignments. The first thing I need to do is get a list of courses and course id's but when I do I'm missing 2/3 of the new semester's courses.

I'm positive that my API call is written correctly as the list is full of courses, it's just missing the two that I need. Is this something on the professor's end?

In case it's useful, I've attached the relevant code, but I don't think there is an issue with it.

Labels (3)
0 Likes
1 Solution
matthew_buckett
Community Contributor

Canvas paginates its results by default and the other courses are probably on the next page. The URL for the next page of results is in the "Link" HTTP header and the documentation about this is at: https://canvas.instructure.com/doc/api/file.pagination.html

The default page size for the courses API is 20 10 (corrected by @James, thanks) results, just adding a parameter to the URL of ?per_page=100 will give you 100 results at once (the maximum for the courses API I think) so this should allow you to get a little further before worrying about pagination.

If you do want to paginate the results the we've had good luck with https://github.com/thlorenz/parse-link-header although you can always just predict what the URLs will be. However Instructure advise against this as they don't guarantee that they won't change the parsing in the future and so prefer you to look in the headers.

View solution in original post