AnsweredAssumed Answered

cURL Header, Pagination Error - Can't Collect Data and Paginate with the same query?

Question asked by Lee Newton on Apr 11, 2019
Latest reply on Apr 19, 2019 by James Jones

Hi,


With PHP, Laravel and cURL, I am trying to retrieve data and then express it in a paginatable form, and seem to be caught between a rock and a hard place.
I am familiar with how to handle pagination in Canvas, (as documented here), and try to do so with this query:

 

$token = $this->accessToken;
$headers = ['Authorization: Bearer ' . $token];

$curl = curl_init();
$url = "https://my.test.instructure.com/api/v1/accounts/1/courses?per_page=30";

 

 

curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => TRUE,
CURLINFO_HEADER_OUT => TRUE,
CURLOPT_URL => $url,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HEADER => 1, //This is the diffference between a paginatable result and a non-paginatable result
CURLOPT_RETURNTRANSFER, TRUE
]);
$resp = curl_exec($curl);
$data = json_decode($resp, true);
dd($data); //if CURLOPT_HEADER => 1, has no data
dd($resp); //if CURLOPT_HEADER => 0, has no pagination links


...


Look at the CURLOPT_HEADER line. When set to 0, then dd($data) returns what it should but dd($resp) returns data without any paginatable links that I can see. When I set it to 1, though, $resp contains a "links" line I can use as the documentation covers, but dd($data) returns null. It seems I can't have it both ways for some reason.

 

Is there anything I can do about this? Any help would be dearly appreciated

Outcomes