Community

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
williamtay
New Member

API call to Enrollment - paginations not working - Keeps loading page 1

Hi all,

Hoping someone can help..

I am trying to retrieve student enrolment details.

I am cycling through the pages manually through the URL..

Eg.

https://XXX.edu.au/api/v1/courses/XXX/enrollments?type=StudentEnrollment&page=1

https://XXX.edu.au/api/v1/courses/XXX/enrollments?type=StudentEnrollment&page=2

https://XXX.edu.au/api/v1/courses/XXX/enrollments?type=StudentEnrollment&page=3

For some reason, every page returns the same 10 students.. as if it is just loading page 1.

Is there something I'm missing?

0 Kudos
2 Replies
werner_huysman1
Community Member

hi,

maybe you should check the docs about pagination: https://canvas.instructure.com/doc/api/file.pagination.html

The response to your API request returns a Link header which contains the link to the next page. You could also try to increase the per_page parameter, which defaults to 10 results, but Instructure states that the limit is unspecified.

James
Community Champion

@williamtay 

As @werner_huysman1 wrote, the issue is about pagination

For most API calls, the page=1, page=2, etc., works. The 10 items is the default unless you specify a per_page query parameter. The maximum value is undocumented, but seems to be 100.

There are some calls, though, that do not support the numeric page. The documentation mentions expensive calls may not return the last page. Enrollments happens to be an expensive call because of all of the information that needs to be returned. Instead of using page numbers, it uses bookmarks instead. Bookmarks are basically encoded values of the last value that was returned, so that when you make the call again, it knows where to pick up. Listing of user page views is another place where bookmarks are used and there are others. Bookmarking for Enrollments Index API in upcoming release has a discussion about the details of the enrollments API.

The way to get those bookmarks is to look at the link headers as described in the documentation. It also means that you cannot blindly call page numbers like you are trying. However, the per_page=100 is independent of the type of pagination, so it can still cut the number of API calls down.