How to deal with pagination in Canvas using PHP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I was trying to use pagination in my requests, I just try to show the Header that contains the "Link" values.
I use Guzzle with PHP
$res_aluno_pag = $client->request('GET', 'courses/'.$course_id.'/enrollments?type[]=StudentEnrollment&state[]=active&per_page=1000', ['headers' => $headers
]);
var_export( $res_aluno_pag->getHeader("Link") );
This is the what appear in my screen
array ( 0 => '; rel="current",; rel="next",; rel="first",; rel="last"', )
But if I use postman, I can see the following result inside the "Headers" tab
<https://pucminas.instructure.com/api/v1/courses/5465/enrollments?role%5B%5D=StudentEnrollment&state%5B%5D=active&page=2&per_page=100>; rel="current",
<https://pucminas.instructure.com/api/v1/courses/5465/enrollments?role%5B%5D=StudentEnrollment&state%5B%5D=active&page=1&per_page=100>; rel="prev",
<https://pucminas.instructure.com/api/v1/courses/5465/enrollments?role%5B%5D=StudentEnrollment&state%5B%5D=active&page=1&per_page=100>; rel="first",
<https://pucminas.instructure.com/api/v1/courses/5465/enrollments?role%5B%5D=StudentEnrollment&state%5B%5D=active&page=2&per_page=100>; rel="last"
How can I use PHP and Guzzle to see the complete text/string that is inside the "Link" Header?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have not used Guzzle, but community developers have created a very nice resource for https://community.canvaslms.com/thread/1500 in various languages. If you figure out how to handle the pagination with Guzzle we'd love to see an example.