AnsweredAssumed Answered

How to deal with pagination in Canvas using PHP

Question asked by Fabio Cunha on Aug 12, 2019
Latest reply on Aug 12, 2019 by James Jones

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?

Outcomes