backdrop-contrib / shopify

Integrate and sync your site with a Shopify store.
GNU General Public License v2.0
0 stars 1 forks source link

Remove page-based pagination for rate limits #2

Open laryn opened 2 years ago

laryn commented 2 years ago

Page-based pagination was deprecated in the Admin API with version 2019-07. Use cursor-based pagination instead.

laryn commented 2 years ago

https://shopify.dev/api/usage/pagination-rest

laryn commented 2 years ago

Related (noted by @argiepiano in shopify_sync_deleted_products):

    // There is an issue with how you are using page_info below. The Shopify API
    // describes this as "page_info: A unique ID used to access a certain page of results."
    // See https://shopify.dev/api/usage/pagination-rest
    // The code here may be the result of an old REST API
    // There are several steps to get pagination. You need to get the Link header
    // and extract the page tokens from there.
    // For the time being I have commented out all page related
    // stuff in this function

    // $options['page_info'] = $page;
laryn commented 2 years ago

From the wrapper API readme:

page_info / pagination support

2019-07 API version introduced a new Link header which is used for pagination (explained here).

If an endpoint supports page_info, you can use $response->link to grab the page_info value to pass in your next request.

Example:

$response = $api->rest('GET', '/admin/products.json', ['limit' => 5]);
$link = $response['link']['next']; // eyJsYXN0X2lkIjo0MDkw
$link2 = $response['link']['previous']; // dkUIsk00wlskWKl
$response = $api->rest('GET', '/admin/products.json', ['limit' => 5, 'page_info' => $link]);