I have created one private shopify app. Which can get almost all the information with product id. But I need one option to get product id of all products in a shop with API. I have tried the option below
shopify.Product.find()
but it shows only first 50 products. But my shop has more than 2.4k products.
4
Answers
Update as of 2019-07: This will no longer work as it has been deprecated and subsequently removed from the Shopify API.
The replacement is detailed in this answer.
Original answer below
Shopify returns paginated responses for lists of resources. The default number of resources per page is
50
, and the default page is1
. Your request is thus equivalent to the following:Shopify allows you to increase the limit per page to 250. Here’s a helper function I use to get all of a given resource:
You use it like this:
You can even pass in parameters. Your question asks specifically for the product ID- if you limit the query to only return the IDs, this will be much, much faster (as it doesn’t have to pull in any of the product variants):
Note that if you have 2.4k products, this may take some time!
Documentation:
https://help.shopify.com/api/reference/product
Thought this might be helpful as well:
Pagination interface has changed in Shopify API, and the old "limit + page" way of doing pagination was removed in api version 2019-07.
In other words: the accepted answer by @Julien will NOT work in this api version and later.
I have re-created the function of the accepted answer using the new way of doing relative cursor based pagination here:
An extension of Lennart Rolland response.
As he stated the preferred answer is no longer applicable in api version 2019-07.
I was unable to get his code sample to work, because of an error "list does not have the function has_next_page()".
So I have written an example using the ‘Link’ header rel=’next’ pagination.