FROM CACHE - en_header

Rest api pagination with since_id

Solved
Giancarmelo
New Member
1 0 0

I need to get all the products in my shop, but when I try to print them, having the limit of 250 per call, I realized that there were no products, the rest call with the since_id does not seem to work.

To test I made the request for the first 10 products, and then I tried to get them 5 to 5 and this was the result.

these are the top 10 products ids:

first 10.JPG

then I made 2 calls to get the first 5 products in the first, and the next 5 in the second using the since_id:

fist 10 5 by 5.JPG

can see the first 5 are correct, but the next 5 do not match. What am I doing wrong ? 

 

Accepted Solution (1)

Accepted Solutions
L_J_K
Shopify Staff
Shopify Staff
402 64 82

This is an accepted solution.

Hey there @Giancarmelo 

Had you tried the first call including since_id=0 along with those fields when trying to get all the products on your store at the beginning? So something like this would return the first ten products I created on my store -   api/2021-10/products.json?fields=id,handle,variants&since_id=0&limit=10 

Then, if I look at those ten products, and take the fifth product's ID,  and then try this following GET. Like so - api/2021-10/products.json?fields=id,handle,variants&since_id={the_fifth_product's id}&limit=5

I diff my results from my first call of ten against my second call for the next 5 after the fifth ID, and the ID's all match ok. I think your mismatch could have something do with the default, products are returned in ascending order by title in the Products API when since_id is not specified. 

There's some further docs here if you need them.  Let me know how that goes!

 

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!

View solution in original post

Replies 2 (2)
L_J_K
Shopify Staff
Shopify Staff
402 64 82

This is an accepted solution.

Hey there @Giancarmelo 

Had you tried the first call including since_id=0 along with those fields when trying to get all the products on your store at the beginning? So something like this would return the first ten products I created on my store -   api/2021-10/products.json?fields=id,handle,variants&since_id=0&limit=10 

Then, if I look at those ten products, and take the fifth product's ID,  and then try this following GET. Like so - api/2021-10/products.json?fields=id,handle,variants&since_id={the_fifth_product's id}&limit=5

I diff my results from my first call of ten against my second call for the next 5 after the fifth ID, and the ID's all match ok. I think your mismatch could have something do with the default, products are returned in ascending order by title in the Products API when since_id is not specified. 

There's some further docs here if you need them.  Let me know how that goes!

 

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
inFace
New Member
3 0 0

The data list is returned in reverse order of creation time, but the since_id reference index is in positive order of time. If the data exceeds the maximum number of pages 250, you will not be able to query the 251 data

 

 

This is my test conclusion, if there are any errors, please forgive me

 

This is a Chinese translation and some descriptions may not be accurate