Shopify REST API Pagination Link Empty

Shopify REST API Pagination Link Empty

November 15, 2023
Issue: I was trying to make a call to the Shopify REST API where I had more than 50-250 results but I am not able to get the Link Header from the cURL Response which contains the Pagination Links. It was working fine in with postman.
Here is solution for this
$curl = curl_init(); 
curl_setopt_array($curl, 
array( CURLOPT_URL => 'https://your-store.myshopify.com/admin/api/2023-07/products.json?fields=variants%2Cid&limit=2',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HEADER =>  1,
  CURLOPT_HTTPHEADER => array(
    'X-Shopify-Access-Token: your_token'  ),
));

$response = curl_exec($curl);

$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = htmlspecialchars(substr($response, 0, $header_size));

var_dump($header);

die;
curl_close($curl);

Below code fix the issue $header = htmlspecialchars(); is required to get link from headers

$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = htmlspecialchars(substr($response, 0, $header_size));

Share This Story, Choose Your Platform!

Lets Discuss On Your Store

Avada Programmer

Hello! We are a group of skilled developers and programmers.

Hello! We are a group of skilled developers and programmers.

We have experience in working with different platforms, systems, and devices to create products that are compatible and accessible.

Go to Top