How to use the REST API to get students from a course?

Jump to solution
DOVKRUGER
Community Member

I wrote some quick perl and python code to get the list of courses from canvas.

 

I can get user data for a single course like this:

https://canvas.instructure.com/doc/api/v1/courses/$course/users?per_page=250

 

where $course is my course number in perl.

However, the max number the API will support appears to be 100. So I need to get the first 100 and link to get the next group. The only docs I can find on paging:

https://canvas.instructure.com/doc/api/file.pagination.html

seems to be more for interactive documents. I don't see anything in the JSON coming back that indicates how to get the next bunch. Any help?

0 Likes
1 Solution
chriscas
Community Coach
Community Coach

Hi @DOVKRUGER,

The pagination info will not be in the JSON, but rather the html response header.  In python, if you use the request library, you can use the .link property of the response to get the current and next links Canvas sends.  I could send you a function I've made to get all pages of a Canvas API request if you have interest and are using python.  If this is part of your perl code, perhaps someone with experience in that language will come in and give a suggestion.

-Chris

View solution in original post