Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
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.
Solved! Go to Solution.
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.
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.
I think the default is 10 without using the per_page parameter, at least it is for me.
You can also use the GraphQL interface to get a list of the current user's courses. It handles pagination differently and you can get all of them in one shot as long as there aren't too many of them (but well over 100). For individual users, that's probably not an issue.
query myCourses {
allCourses {
_id
name
}
}
Huh, the more you know. Thanks for your help this is exactly what I needed
To participate in the Instructure Community, you need to sign up or log in:
Sign In