Solved

Not getting store all products using rest API

tejash_patel_iw
Tourist
23 0 2

Hello

 

When I get to store all products using rest API with 250 limits then I am not getting all products after specified since_id.

https://shopify.dev/api/admin-rest/2022-10/resources/product

 

For example,
Total active products are 3000
In the first call I am getting 250 products then I passed the last product id in since_id, after 3 calls I am not getting any products
It means I am getting only 750 products

 

How can I resolve this issue?

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1322 217 457

This is an accepted solution.

Hey @tejash_patel_iw - you should be able to use the "order" query parameter in the HTTP request using REST to order the product list by a given criteria. For example, here's a query I just tested on my store to confirm the functionality:

https://[mystore].myshopify.com/admin/api/2022-07/products.json?order=created_at+desc&limit=5

This orders my products by their created_at timestamp from the earliest created to the newest. If there are more products represented in products.json after the limit I've set, the API call's response header should contain a "link" field that looks like this:
 

https://[mystore].myshopify.com/admin/api/2022-07/products.json?limit=5&page_info=eyJvcmRlciI6ImNyZWF0ZWRfYXQgZGVzYyIsImxhc3RfaWQiOjc5NzQ0MDY5MTQwNzAsImxhc3RfdmFsdWUiOiIyMDIyLTExLTI1IDE3OjMxOjA1LjAwMDAwMCIsImRpcmVjdGlvbiI6Im5leHQifQ>; rel="next"

 

You can then use that link to parse through the remaining items - each subsequent link header will follow a similar formatting. This method is what we call our "link header" method for relative pagination for requests and we have a bit more information on this here in a great blog post

Hope this helps - let us know if we can clarify further. 

 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 7 (7)

Jason
Shopify Expert
11190 225 2283
  1. What is the response you're getting back when it fails?
  2. Have you checked for errors?
  3. Are you sure you're not hitting a rate limit? 
  4. Got an example requestID in the header response from when it failed?

^ There's some starting questions to help build some context for the forum members.

★ I jump on these forums in my free time to help and share some insights. Not looking to be hired, and not looking for work. http://freakdesign.com.au ★
tejash_patel_iw
Tourist
23 0 2

Hi

1. I am getting blank product JSON: https://prnt.sc/XIKBpszX2sac
2. Not getting any errors
3. Yes
4. Here is a full response of the header:  https://prnt.sc/YLg3puvKXaQc
The request ID is: 4d49d523-6624-410c-80ef-fbb7703e05b4

Let me know if I am doing anything wrong

Thanks.

ShopifyDevSup
Shopify Staff
1322 217 457

Hi @tejash_patel_iw 👋

 

Thanks for sharing the X-Request-ID!

 

It looks like product ID 7037068345437 is the very last product ID in this store, so it would be expected that setting `since_id=7037068345437` would return no products.  You can check this by using a query like the below: 

 

{
  products (first:1, reverse:true, sortKey:ID){
    nodes {
      id
    }
  }
}

 

Which returns:

{
  "data": {
    "products": {
      "nodes": [
        {
          "id": "gid://shopify/Product/7037068345437"
        }
      ] ...
     

Hope that helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

tejash_patel_iw
Tourist
23 0 2

Hi


I have checked as you suggest to using graphQL and yes this product(7037068345437) is the last product

But I am facing this issue with the rest API

 

In my store total products are 4190 = https://prnt.sc/VLuGlPY3rt1s
We have used the 250 product limit in each call
So the total calls are 4190/250 = 16.79 (Approx. 17 calls) but we get only 14 calls then after we didn't get any products

 

Here I mention the last product id
1st call last product id is 7036722544733
2nd call last product id is 7036732571741
3,4, likewise
14th call last product id is 7037068345437

 

Last call request id is = c78cab06-38af-4ee2-a11e-ed783a22ab0c
Header response = https://prnt.sc/66dtZ1tW5gL6
Response = https://prnt.sc/R8rFBD2gpKWU

 

Is there any way to get the product list in sorted order as you mention sortKey in graphic but I want to fulfill this with the rest API

 

How can I fulfill this requirement?

 

Note: This issue working fine with the 100 limits only issue happened with the 250 product limit.

ShopifyDevSup
Shopify Staff
1322 217 457

This is an accepted solution.

Hey @tejash_patel_iw - you should be able to use the "order" query parameter in the HTTP request using REST to order the product list by a given criteria. For example, here's a query I just tested on my store to confirm the functionality:

https://[mystore].myshopify.com/admin/api/2022-07/products.json?order=created_at+desc&limit=5

This orders my products by their created_at timestamp from the earliest created to the newest. If there are more products represented in products.json after the limit I've set, the API call's response header should contain a "link" field that looks like this:
 

https://[mystore].myshopify.com/admin/api/2022-07/products.json?limit=5&page_info=eyJvcmRlciI6ImNyZWF0ZWRfYXQgZGVzYyIsImxhc3RfaWQiOjc5NzQ0MDY5MTQwNzAsImxhc3RfdmFsdWUiOiIyMDIyLTExLTI1IDE3OjMxOjA1LjAwMDAwMCIsImRpcmVjdGlvbiI6Im5leHQifQ>; rel="next"

 

You can then use that link to parse through the remaining items - each subsequent link header will follow a similar formatting. This method is what we call our "link header" method for relative pagination for requests and we have a bit more information on this here in a great blog post

Hope this helps - let us know if we can clarify further. 

 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

zahid3d29
Shopify Partner
73 5 28

Hello, I got a simple solution for it. 

If your code like this 

shopify_call($token, $shop, "/admin/api/2023-04/products.json", array(), 'GET');

 

then just add this parameter after 

.josn

like

.json?limit=250&

 

Hope it will work for you.

 

Thanks

Need a Shopify developer? Chat on WhatsApp
- For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
- Your Coffee Tip , my code a perfect blend!   ❤️

uisce
Visitor
1 0 0

 

Hey there!

 

I know a template that might help https://www.getlazy.ai/templates/shopify-api-get-all-products-30a1e6a7-0105-4858-8b6a-e94f6be8f4a9?q...

 

It's a FastAPI application that connects to your Shopify store and retrieves all products in JSON format. The cool part is that it handles the paginated responses for you, ensuring you get all your products without hassle.

 

To get started, just hit "Start with this Template" on the platform. It'll preload the code for you. Before deploying, make sure to set up your environment secrets by adding your Shopify API key and Admin API token. The template walks you through it.

 

Once deployed, you'll receive a dedicated server link. For fetching all products, make a POST request to the /products endpoint with your store URL in the request body.