API Pagination Link header empty

592 views
Skip to first unread message

jos...@gmail.com

unread,
Mar 12, 2013, 7:09:46 PM3/12/13
to canvas-l...@googlegroups.com
So I am testing out the API and I am running into an issue when pulling all users. I have more then 10 for my account, it pulls the first 10 but when I check the Link header for the next, first, last the URLs are not populated.

My Response:
[Link] => ; rel="next",; rel="first",; rel="last"

Expected Response according to this page: https://canvas.instructure.com/doc/api/file.pagination.html

Link: <https://<canvas>/api/v1/courses/:id/discussion_topics.json?page=2&per_page=10>; rel="next",
      <https://<canvas>/api/v1/courses/:id/discussion_topics.json?page=1&per_page=10>; rel="first",
      <https://<canvas>/api/v1/courses/:id/discussion_topics.json?page=5&per_page=10>; rel="last"

As you can see my URLs are empty...

I am using PHP, here is my code:

<?php
global $authorization;
$authorization
= 'xxxxxxxxxxxxxxxxxx';

function canvas_get($url) {
       
global $authorization;
        $options
= array(
                       
'connecttimeout' => 120, // timeout on connect
                       
'timeout' => 120, // timeout on response
                       
'redirect' => 10, // stop after 10 redirects
       
);
        $headers
= array(
                       
'Authorization' => 'Bearer ' . $authorization
       
);
        $request
= new HttpRequest($url);
        $request
->setMethod(HTTP_METH_GET);
        $request
->setContentType("application/json");
        $request
->setOptions($options);
        $request
->setHeaders($headers);
        $request
->send();
       
return array('status_code'=>$request->getResponseCode(), 'response'=>$request->getResponseBody(),'header'=>$request->getResponseHeader());
}

$course_results
= canvas_get('https://xxxxxxxxx.com//api/v1/accounts/1/users');
echo
'<pre>';
print_r
($course_results['header']);
echo
'</pre>';

?>
Enter code here...

Any ideas why the urls are not getting populated?

ry...@ryanhiebert.com

unread,
Mar 12, 2013, 8:46:27 PM3/12/13
to canvas-l...@googlegroups.com
The last time I looked at this, the discussion topics endpoint didn't paginate at all. If you have more then 10 discussions, it'll show all of them at once. Check that.

There's another endpoint (recent_students, I think) that doesn't give the pagination links if there are less than 10, so you can't assume that the pagination links will be there.

Hope that helps,

Ryan

--
 
---
You received this message because you are subscribed to the Google Groups "Canvas LMS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to canvas-lms-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jos...@gmail.com

unread,
Mar 18, 2013, 6:10:46 PM3/18/13
to canvas-l...@googlegroups.com
But I for sure have more than 10 users and it is only returning 10. How can I get the rest?

jos...@gmail.com

unread,
Mar 22, 2013, 2:36:09 PM3/22/13
to canvas-l...@googlegroups.com, jos...@gmail.com
To answer my own question a while loop should work just fine to check against the number of array elements and if it is equal to the number limit get the next page.

Ryan Hiebert

unread,
Mar 23, 2013, 9:30:08 PM3/23/13
to canvas-l...@googlegroups.com, jos...@gmail.com, canvas-l...@googlegroups.com

I thought your issue was that there was no next link. Did you end up having to construct it manually?


Sent from Mailbox for iPhone

jos...@gmail.com

unread,
Mar 25, 2013, 2:02:35 PM3/25/13
to canvas-l...@googlegroups.com, jos...@gmail.com
That is exactly what I did. Seems to work just fine.
Reply all
Reply to author
Forward
0 new messages