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

Canvas cURL pagination: doesn't include "last" page link?

For my project I need to get all the pages of data for a project.

I can make cURL requests on data endpoints and get all the pages I want. For example, see this DD of some page data that includes all four links: "Current", "Next", "Last" and "First":

array:4 [  0 => "Link: <>; rel="current""   1 => "<>; rel="next""   2 => "<>; rel="first""   3 => "<>; rel="last"\r"]

However, sometimes when I get page link data, they will not include the "last" field, I'll only have the first three to work with: "Current", "Next" and "First":

array:3 [  0 => "Link: <>; rel="current""   1 => "<>; rel="next""   2 => "<>; rel="first"\r"]

To clarify, in that above example, I can confirm there are far more pages than just two, there are at least seven. So I know there are many more pages to fetch, but for some reason I don't understand, there isn't a "last" link available.

For my project, I want to be able to always link to the last page, so having that "Last" link would be very valuable.

I have read the Canvas API documentation on Pages, on Endpoints, and on Courses and Users among other pages, but nothing there seems to have the solution.

Here are two URLs that make sure to include the "last" page:



Here are some which don't.



Does anyone know how I might be able to get it? Or have any ideas that might point me in the right direction? Any help at all would be greatly appreciated

Labels (4)
0 Kudos
3 Replies
New Member

I have recently come across this problem too. API calls which previously returned the "last" url are now not doing so. I can only assume it is a Canvas bug.

0 Kudos
Community Participant

Dude!  Me too!  Apparently the Link header was changed to return a dictionary instead of an array or string.  So now, my course archiving project is undergoing a rewrite.  Was this an announced change?  If so, I totally missed it!

So now the Link header looks like this:

{'current': {'rel': 'current',
'url': ''},
'first': {'rel': 'first',
'url': ''},
'last': {'rel': 'last',
'url': ''},
'next': {'rel': 'next',
'url': ''}}




0 Kudos

I've checked with Canvas support and they let me know that you can't rely on the "last" link being available as it won't be computed if it's too "expensive".