Full product listing using REST API

Hello:

We want to retrieve a full list of our published products using the REST API at https://shopify.dev/docs/api/admin-rest/2023-01/resources/product#get-products

The return list is limited to up to 250 items, but there seems to be no way to offset repeat calls to get the full product list. How can we do this?

Hello @Moddo

Thank you for reaching out to the Shopify community.

In your pursuit of retrieving all published products via the REST API, it is worth noting that Shopify provides a maximum of 250 products per API call. To overcome this limitation, it is necessary to utilize the “since_id” parameter, which requires passing the ID of the last product obtained in the previous call.

Allow me to illustrate this process with an example:

  • Initiate a GET request in the following manner:

https://cheetosr.myshopify.com/admin/api/2023-01/products.json?since_id=0

  • Once you have received the product data, locate the ID of the last product in the array and store it in a variable. Let us assume, for instance, that the last product’s ID is: 8441676824850 Store this value in a variable named “since_id.”

  • For subsequent API calls, construct the URL as follows:

https://cheetosr.myshopify.com/admin/api/2023-01/products.json?since_id=8441676824850

Repeat this process iteratively until you receive an empty set in response from the API.

I kindly request that you try implementing these suggested solutions and inform me of their efficacy in resolving the issue of retrieving all products. Please do not hesitate to reach out if you require further assistance or clarification.

1 Like

Hi Moddo,

There is a ‘Link’ header in the response that gives you a link to the next page and the previous page of results. You can find info about how it here: https://shopify.dev/docs/api/usage/pagination-rest

Here is an example snippet:

shop.with_shopify_session do
  products = ShopifyAPI::Product.all(limit: 250)
  products.each do |p|
    # your logic
  end
  # next page
  while ShopifyAPI::Product.next_page?
    products = ShopifyAPI::Product.all(
      limit: 250, page_info: ShopifyAPI::Product.next_page_info)
    products.each do |p|
      # your logic
    end
  end
end