Currently i can fetch as per shopify’s API limit of 250 products per call and echo this out. I have done some research and found that i need to paginate the request on the overall count of products [5000 products / 250 products per page = 20 pages] in the store.
I want get all products in shopify
so I tried to solved.
but i can not get all products.
the result is always ‘error…..’.what is problem?
$pages = ceil($products_cnt->count/250); // Count products / 250
for($i = 0; $i < $pages; $i++){
$api_url = 'https://apikey:[email protected]';
$get_url = $api_url . '/admin/products.json?limit=250&page='.($i+1);
$products_content = @file_get_contents( $get_url );
if (!empty($products_all)) {
print_r('ok');
} else {
print_r('error.....');
}
$products_json = json_decode( $products_content, true );
$products = $products_json['products'];
2
Answers
I guess you have a problem with Shopify API rate limit. But to be sure of this need to check the response from the Shopify API. For the HTTP request better to use the curl or some HTTP client package for example the Guzzle.
Try instead of the
@file_get_contents($get_url)
use this code:The Pagination method you are trying to use has been deprecated. Shopify introduced new cursor based pagination from API version 2019-07. To read more about Cursor based pagination, head over to Shopify Docs for Cursor based Pagination. It is better if you use some PHP library that offers rate limiting and other things. However, a sample implementation using cURL would look something like below. Check code comments for details.
Response Headers parsing function by Geoffrey