Cursor-Based Pagination Under Shopify’s Latest API

Shopify will no longer use the page parameter in their latest 2019-07 API changes, here’s an example code for cursor-based pagination using the phpclassic/php-shopify package.

This code was tested on API version 2020-01.

PHP 7.2 + Required

This code assumes you’re executing the PHP script from your terminal / command prompt.

Install the Dependencies

composer require phpclassic/php-shopify

The Code



$config = array(
    'ShopUrl' => '',
    'ApiKey' => 'apikey',
    'Password' => 'password',

$shopify = PHPShopify\ShopifySDK::config($config);

$productResource = $shopify->Product();
$products = $productResource->get(['limit' => 250]);
$nextPageProducts = $productResource->getNextPageParams();
$nextPageProductsArray = [];

while ($nextPageProducts) {
    $nextPageProductsArray = $productResource->get($productResource->getNextPageParams());
    $products = array_merge($products, $nextPageProductsArray);
    $nextPageProducts = $productResource->getNextPageParams();

echo 'Total Products: ' . count($products) . PHP_EOL;

Follow the link for more information on cursor-based pagination change from Shopify.

Leave a reply:

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Site Footer

Sliding Sidebar


Nice to meet you, my name is Ryan and I build stuff for the web. Welcome to my website where you can learn about me and my interests.