When GETting a list of products via Shopify API, how does pagination work on the server side?

久未见 提交于 2019-12-11 03:28:55

问题


Scenario: Store with 1000 products; need to download them all. Requests for products are limited to a maximum of 250 products per call, and apparently the API may or may not return the "limit" requested. For example, a call with limit=250 may return less than 250 items, from what I've observed. So, to get 1000 products a minimum of 4 calls are needed.

The following requests are issued:

#1  GET /admin/products.xml?limit=250&page=1 (returned the first 250 products 1-250)
#2  GET /admin/products.xml?limit=250&page=2 (returned the next 250 products 251-500)
#3  GET /admin/products.xml?limit=250&page=3 (****returned only 200 products 501-700**)
#4  GET /admin/products.xml?limit=250&page=4 (****what does it return here?**)

So, the question is about pagination on the server, which will define what happens in line #4 above:

1) Does the API perform smart pagination, in which it knows that the previous request returned only 200 products and therefore the next page must return a list starting with product number 701?

or

2) Does it perform blind pagination, in which a request for page 4 will always start with product number 751, regardless of what happened in the last call?


回答1:


Use the /admin/products/count.json to get the count of all products. Then divide that number by 250 to get the total amount of pages.




回答2:


You can pass params in shopify API using shopify api gem if in rails or can directly use Shopify APIs for send params.

ShopifyAPI::Product.find(:all, params: { page: parmas[:page], 
                                         limit: 10, 
                                         title: params[:search]
                                       })


来源:https://stackoverflow.com/questions/12249196/when-getting-a-list-of-products-via-shopify-api-how-does-pagination-work-on-the

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!