Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
Hi,
I seem to have an issue with interfacing with the Canvas API from my tool (I'm a tool provider).
In Canvas we have a course with 20+ sections. When a launch of my tool is pefrormed from the instructor, we interface with Canvas (via its Oauth API) and check how many sections are present in the course, using the API url:
/api/v1/courses/:course_id/sections?include=total_students
What we see is baffling: we only receive up to 10 courses as a result. Is there some kind of limit we're hitting here with the Canvas API, or is the amount of sections that can be returned customizable somewhere so we can get all of them?
This is particularly critical for us so any feedback would be greatly appreciated.
Best
Davide
Solved! Go to Solution.
Hi @Davidemolin
There is a "pagination" setting in the API that defaults to returning 10 results. See https://canvas.instructure.com/doc/api/file.pagination.html
I think you're probably running into pagination. By default, the API will only return the top 10 results. You can change the call to return up to 100 results (&per_page=100) or use a loop to get the next page of results. I hope this helps.
Pagination - Canvas LMS REST API Documentation (instructure.com)
Hi @Davidemolin
There is a "pagination" setting in the API that defaults to returning 10 results. See https://canvas.instructure.com/doc/api/file.pagination.html
Thank you, much appreciated!
I think you're probably running into pagination. By default, the API will only return the top 10 results. You can change the call to return up to 100 results (&per_page=100) or use a loop to get the next page of results. I hope this helps.
Pagination - Canvas LMS REST API Documentation (instructure.com)
Thank you! I found the "per_page" query parameter while inspecting the response headers; it now works as expected. thanks!
Hi @Davidemolin,
Just to emphasize what @JennyDruckrey mentioned, the per_page parameter currently can only be set up to 100 (and even though I don't think that's ever changed since Canvas was introduced, nothing is stopping Instructure from reducing that limit tomorrow). The best way to handle this, in my opinion, is to use the link header as described in the previously linked pagination documentation page (or do this and also try a per_page number in the first api call to slightly increase performance). It may be slightly more work up front, but doing things that way should pretty much guarantee your code will never break with future changes and will always include all results.
-Chris
Thank you @chriscas ,
yes, I'm now parsing the link header so I can load additional pages if necessary. Thanks again for the support, it's really appreciated.
To participate in the Instructure Community, you need to sign up or log in:
Sign In