Closed svishalgarg closed 4 years ago
Pagination is already supported, if you are pointing to any specific feature, please give me the documentation so that I can confirm.
@svishalgarg
Also please note that, you can provide ApiVersion
in the $config
array to use any version of API you want.
thank you @tareqtms for replying.
i want to know, how can I use below api for pagination of products, orders and other endpoint. https://help.shopify.com/en/api/guides/paginated-rest-results
page parameter is no longer supported in new versions
@svishalgarg Also please note that, you can provide
ApiVersion
in the$config
array to use any version of API you want.
Hi @tareqtms ,
Should I set it up like this?
'ApiVersion' => '2019-10'
tks
@oscarfabiano Yes
@tareqtms thanks for replying , I am talking about new pagination updates , Please check below url : https://help.shopify.com/en/api/guides/paginated-rest-results
page parameter is no longer supported with new versions, with new versions, it send pagination data in response headers.
with your sdk , what is the process to use this pagination ?
thanks
Try something like this:
$params = ['page_info' = '__Page_Info_', 'limit' => '___Limit___'];
$shopify->Product->get($params);
how to get page info data ?, is there any function in any class that returns response headers? thanks
That should be in the header of the first request. So for the first request, you can send only the limit
.
Btw, not sure, if you can get the headers from the current implementation. I will check on that later and let you know.
that's what i was asking, "how to retrieve response headers after making api call". hope to get updates soon, as pagination is must for orders, products etc.
thanks @tareqtms . 👍
My proposal would be something like this (to keep it backward compatible). Of course the function/attribute names are for discussion
The pagination headers looks like this:
<https://your-shop-name.myshopify.com/admin/api/2019-10/products.json?page_info=123hash123>; rel="next"
and this is how a previous page header looks like:
<https://your-shop-name.myshopify.com/admin/api/2019-10/products.json?page_info=123hash123>; rel="previous"
So you can do something like this:
$shopify = new PHPShopify\ShopifySDK($config);
$products = $shopify->Product->get();
if($shopify->Product->lastResourceContainsNextPageInfo()) {
while(true) {
$products = array_merge($products, $shopify->Product->get(['page_info' => $shopify->Product->getNextPageInfo()]));
if(!$shopify->Product->lastResourceContainsNextPageInfo()) {
break;
}
}
}
@aalwash I liked the idea. I need a bit more time to think deeply. But you are welcome to submit a PR. I will merge it if I don't find any better alternative.
@tareqtms if make sense , you can also think doing like this simple way
$products = $shClient->Product->get();
$lastResponse = $shClient->getLastResponseInfo();
getLastResponseInfo method can return response information along with formatted header info. headers also contains info about api limits etc, so that will be accessible too.
I am not sure if its a good idea but you can check if it is
Thank you.
@svishalgarg is the 'easiest' fix and should do the job as well It's less "code-friendly" since you have to extract your own headers to find the next/previous pagination links
Maybe implement both, since the last response info contains other headers in case someone needs to extract this
@aalwash I liked the idea. I need a bit more time to think deeply. But you are welcome to submit a PR. I will merge it if I don't find any better alternative.
@tareqtms - I just created a pull request (https://github.com/phpclassic/php-shopify/pull/125) that attempts to do what @aalwash described. Seems to work in my test environment. Please review and let me know what you think. ApiVersion needs to be updated to "2019-07" to get the new header in most endpoints.
@rjacobso The changes are not backward-compatible, so we cannot merge this now. (If we do, it may break many sites using the package.) For now, looking for a backward-compatible solution.
deadline is UPDATE DEADLINE: APR 01, 2020 fyi
Hmm, I already tried to keep it backward compatible How is this not backward compatible?
I'd be happy with a 2.0.0 version instead of BC.
Plus it should just document what people need to fix the BC issue.
@aalwash - it was not backwards compat because I changed the return types of some methods. @tareqtms - Last week I closed #125 and tried again with #136 . I think this accomplishes the original @aalwash goal without changing any existing functionality.
I also noticed (after I submitted mine) that there is a pull request #134 to do something similar but I did not get a chance to test it yet.
Does anyone have any example code on how to use this? We just need to loop through all products, but I am struggling to keep up with the threads / PR's on this subject. Many thanks.
Does anyone have any example code on how to use this? We just need to loop through all products, but I am struggling to keep up with the threads / PR's on this subject. Many thanks.
I supose you do:
how to implement pagination in new API anyone can give some light ?
Something like:
$config = array(
'ShopUrl' => $shopify_shop,
'ApiKey' => $shopify_api_key,
'Password' => $shopify_api_pass,
);
$shopify = ShopifySDK::config( $config );
$filters = [
'limit' => 250,
];
$product_resource = $shopify->Product();
$products = $product_resource->get($filters);
$next_page = $product_resource->getNextPageParams();
while ($next_page) {
$next_page_products = $product_resource->get($product_resource->getNextPageParams());
$products = array_merge($products, $next_page_products);
$next_page = $product_resource->getNextPageParams();
}
@rjacobso Thanks for the example code. @binipinki You can follow #101 for more info related to this.
shopify made some changes to api like pagination etc. I hope you will implement these changes