Skip to content

Pagination on a subresource #18

Open

Description

@jtallieu

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.

Activity

  1. bookernath commented on Oct 10, 2016

    @bookernath
    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.
  2. sabotagebeats commented on Aug 3, 2017

    @sabotagebeats

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions