Skip to content

Unable to get ['meta']['pagination']['total_pages'] from products = api.Products.all()  #59

Closed

Description

@sabotagebeats

Expected behavior

in requests library, total_pages returned in json.

Actual behavior

products = api.Products.all()
does not return all items, it returns only the first page of items.

products = api.Products.all(page=2)
produces second page but does not return total pages.

products = api.Products.all(limit=250)
produces 250 items, no total_pages

count = api.Products.count()
products = api.Products.all(limit=count)

fails with exception: bigcommerce.exception.ClientRequestException: 413 Request Entity Too Large @ products: [{"status":413,"message":"The specified limit exceeds the maximum allowed.","details":{"max_limit":250}}]

This makes it impossible to iterate pagination within the bigcommerce-api-python library.

Steps to reproduce behavior

api = bigcommerce.api.BigcommerceApi(client_id=clientID, store_hash=store_hash, access_token=accessToken)
count = api.Products.count()
products = api.Products.all(limit=count)

Activity

  1. bookernath commented on Jul 24, 2017

    @bookernath
    Contributor

    Hi @sabotagebeats, the pagination values you're referring to come from the V3 BC API, whereas this library is for the older V2 API and has not yet been updated for V3.

    For V2, best practice is to take the count and your desired page size to determine the total number of pages over which you'll need to paginate to get all objects, and then paginate them. As per your error message, the maximum page size is 250.

    To use the V3 API with this library, you can create an OAuthAPIConnection object directly and change the pathing to /v3/ like so:

    v3client = bigcommerce.connection.OAuthConnection(client_id=client_id,
                                                          store_hash=store_hash,
                                                          access_token=access_token,
                                                          api_path='/stores/{}/v3/{}')
    

    This will allow you to use the low-level CRUD interface to interact with the JSON directly, as a workaround for now. An API call would then look like this:

    products_response = v3client.get('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/catalog/products?limit=%s&page=%s'
                                       % (page_size, current_page))
    

    And you could access the pagination object in the response like this:

    products_response['meta']['pagination']

  2. sabotagebeats commented on Jul 24, 2017

    @sabotagebeats
    Author
  3. sabotagebeats commented on Jul 25, 2017

    @sabotagebeats
    Author

    Thanks this seems to work:

    pCounter = 1 #count the pages - 1st page
    totalpages = 1 #currently total pages is 1, changes upon loading api
    lookupcategory = 0 #0 for all
    
    api = bigcommerce.api.BigcommerceApi(client_id=clientID, store_hash=store_hash, access_token=accessToken)
    count = api.Products.count(category=lookupcategory)
    totalpages = count // 250
    totalpages = totalpages + 1
    print 'There are', count, 'items','in', totalpages, 'total pages'
    
    while pCounter <= totalpages:
        product = api.Products.all(category=lookupcategory, page=pCounter)
        pCounter += 1
    
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