Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination on a subresource #18

Open
jtallieu opened this issue Sep 5, 2014 · 2 comments
Open

Pagination on a subresource #18

jtallieu opened this issue Sep 5, 2014 · 2 comments

Comments

@jtallieu
Copy link
Contributor

jtallieu commented Sep 5, 2014

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
Copy link
Contributor

Hey there,

Two things:

  1. You can add the limit=250 parameter to get the maximum number of items per page of 250
  2. 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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants