How to deal with pagination in Canvas using PHP

Jump to solution
fabiocunha
Community Explorer

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?

Labels (1)
1 Solution
robotcars
Community Champion

 @fabiocunha 

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.

View solution in original post