Pagination on a subresource
Opened this issue · 2 comments
jtallieu commented
I recently ran across a problem where a customer has 100 skus for a product. The API only allows me to get the first 50.
opts.update({"limit": 50, "page": 1})
for product in self.con.Products.all(**opts):
for sku in product.skus():
print sku
It would be nice if we could pass parameters to the sub resource's all/get method and have it cascade to the connection instance to perform the gets
stop = False
skuopts = {"limit": 50, "page": 1}
while not stop:
for sku in product.skus(**skuopts):
print sku
My other option would be to iterate using the SubResource explicitly and passing in the product id and the product's connection, but the connection property is privatized.
opts.update({"limit": 50, "page": 1})
for product in self.con.Products.all(**opts):
stop = False
skuopts = {"limit": 50, "page": 1}
while not stop:
for sku in self.con.ProductSkus.all(product.id, product._connection, **skuopts):
print sku
This would require exposing the connection object from within the parent resource.
bookernath commented
Hey there,
Two things:
- You can add the limit=250 parameter to get the maximum number of items per page of 250
- We handle pagination much more nicely in the new V3 APIs, and we'll look at updating this client soon - and including a pagination method. We have swagger docs for the new V3 APIs which can be used to auto-generate clients, though.
sabotagebeats commented
this worked for me to increment pagination - thanks @bookernath
onepage = 250
count = api.Products.count()
pages = ( count // onepage ) + 1
pagecounter = 1
while pagecounter <= pages:
items = api.Products.all()
pagecounter += 1
print items