Python client library for Bigcommerce API

Overview

Bigcommerce API Python Client

Build Status Package Version

Wrapper over the requests library for communicating with the Bigcommerce v2 API.

Install with pip install bigcommerce or easy_install bigcommerce. Tested with python 3.8, and only requires requests and pyjwt.

Usage

Connecting

import bigcommerce

# Public apps (OAuth)
# Access_token is optional, if you don't have one you can use oauth_fetch_token (see below)
api = bigcommerce.api.BigcommerceApi(client_id='', store_hash='', access_token='')

# Private apps (Basic Auth)
api = bigcommerce.api.BigcommerceApi(host='store.mybigcommerce.com', basic_auth=('username', 'api token'))

BigcommerceApi also provides two helper methods for connection with OAuth2:

  • api.oauth_fetch_token(client_secret, code, context, scope, redirect_uri) -- fetches and returns an access token for your application. As a side effect, configures api to be ready for use.
  • BigcommerceApi.oauth_verify_payload(signed_payload, client_secret) -- Returns user data from a signed payload.

Accessing and objects

The api object provides access to each API resource, each of which provides CRUD operations, depending on capabilities of the resource:

api.Products.all()                         # GET /products (returns only a single page of products as a list)
api.Products.iterall()                     # GET /products (autopaging generator that yields all
                                           #                  products from all pages product by product.)
api.Products.get(1)                        # GET /products/1
api.Products.create(name='', type='', ...) # POST /products
api.Products.get(1).update(price='199.90') # PUT /products/1
api.Products.delete_all()                  # DELETE /products
api.Products.get(1).delete()               # DELETE /products/1
api.Products.count()                       # GET /products/count

The client provides full access to subresources, both as independent resources:

api.ProductOptions.get(1)                  # GET /products/1/options
api.ProductOptions.get(1, 2)               # GET /products/1/options/2

And as helper methods on the parent resource:

api.Products.get(1).options()              # GET /products/1/options
api.Products.get(1).options(1)             # GET /products/1/options/1

These subresources implement CRUD methods in exactly the same way as regular resources:

api.Products.get(1).options(1).delete()

Filters

Filters can be applied to all methods as keyword arguments:

customer = api.Customers.all(first_name='John', last_name='Smith')[0]
orders = api.Orders.all(customer_id=customer.id)

Error handling

Minimal validation of data is performed by the client, instead deferring this to the server. A HttpException will be raised for any unusual status code:

  • 3xx status code: RedirectionException
  • 4xx status code: ClientRequestException
  • 5xx status code: ServerException

The low level API

The high level API provided by bigcommerce.api.BigcommerceApi is a wrapper around a lower level api in bigcommerce.connection. This can be accessed through api.connection, and provides helper methods for get/post/put/delete operations.

Accessing V3 API endpoints

Although this library currently only supports high-level modeling for V2 API endpoints, it can be used to access V3 APIs using the OAuthConnection object:

v3client = bigcommerce.connection.OAuthConnection(client_id=client_id,
                                                  store_hash=store_hash,
                                                  access_token=access_token,
                                                  api_path='/stores/{}/v3/{}')
v3client.get('/catalog/products', include_fields='name,sku', limit=5, page=1)

Managing OAuth Rate Limits

You can optionally pass a rate_limiting_management object into bigcommerce.api.BigcommerceApi or bigcommerce.connection.OAuthConnection for automatic rate limiting management, ex:

import bigcommerce

api = bigcommerce.api.BigcommerceApi(client_id='', store_hash='', access_token=''
                                     rate_limiting_management= {'min_requests_remaining':2,
                                                                'wait':True,
                                                                'callback_function':None})

min_requests_remaining will determine the number of requests remaining in the rate limiting window which will invoke the management function

wait determines whether or not we should automatically sleep until the end of the window

callback_function is a function to run when the rate limiting management function fires. It will be invoked after the wait, if enabled.

callback_args is an optional parameter which is a dictionary passed as an argument to the callback function.

For simple applications which run API requests in serial (and aren't interacting with many different stores, or use a separate worker for each store) the simple sleep function may work well enough for most purposes. For more complex applications that may be parallelizing API requests on a given store, it's adviseable to write your own callback function for handling the rate limiting, use a min_requests_remaining higher than your concurrency, and not use the default wait function.

Further documentation

Full documentation of the API is available on the Bigcommerce Developer Portal

To do

  • Automatic enumeration of multiple page responses for subresources.
Comments
  • dependency on streql

    dependency on streql

    The pip install fails to install streql on python 2.7 on Windows7. It complains that it cannot find vcvarsall.bat. I looked through the API and noticed that streql is only imported, but not used in the code. I was able to use the api on Windows7 by removing that line in connection.py. I don't want to have to install microsoft Visual Anything unless I have to.

    opened by jtallieu 12
  • 406 Not Acceptable ({

    406 Not Acceptable ({"error":"Invalid format."}) during api.oauth_fetch_token call

    Expected behavior

    api = bigcommerce.api.BigcommerceApi( client_id=config['bigcommerce'].get('client_id'), store_hash=context, access_token='')

    token = api.oauth_fetch_token( config['bigcommerce'].get('client_secret'), code, context, scope, config['bigcommerce'].get('redirect_uri')) print(token)

    {'access_token': '***', 'scope': '***', 'user':***, 'context': '***'}

    Actual behavior

    Python 3.6.3 bigcommerce==0.18.0

    api = bigcommerce.api.BigcommerceApi( client_id=config['bigcommerce'].get('client_id'), store_hash=context, access_token='')

    token = api.oauth_fetch_token( config['bigcommerce'].get('client_secret'), code, context, scope, config['bigcommerce'].get('redirect_uri'))

    bigcommerce.exception.ClientRequestException: 406 Not Acceptable @ https://login.bigcommerce.com/oauth2/token: b'{"error":"Invalid format."}'

    Steps to reproduce behavior

    Upgrade bigcommerce to 0.18.0 (from the bigcommerce==0.17.3)

    pip install bigcommerce==0.18.0 running in powershell terminal

    opened by Hitoki 11
  • Python API Client overhaul

    Python API Client overhaul

    Decided to update the client, as it wasn't really working.

    Replaced httplib2 with requests and rewrote most of it. Now (should) support everything the API can do. Not tested extensively; is probably buggy as heck.

    opened by bc-jackiehuynh 9
  • iter_all() Automatic Paging

    iter_all() Automatic Paging

    What?

    Main thing is I added automatic paging to the all method of ListableApiResource. With this pull it returns a generator with all of the objects. It does this by requesting pages from the api till it returns a empty list.

    Also cleaned up some warts i found while going thought the code.

    Happy to take a similar approach for ListableApiSubResource resource however I am not sure of the semantics of paging subresources.

    opened by surbas 8
  • Prepare for 0.11.0 release

    Prepare for 0.11.0 release

    • Update package definition in setup.py
    • Update changelog
    • Update license year
    • Switch to Restructured Text for README so we can use the same file for GitHub and PyPi
    • Minor updates in README
    opened by mattolson 7
  • I'm getting a memory address with each request I send.

    I'm getting a memory address with each request I send.

    Every time I send a GET request to pull data from Big Commerce, I get a Memory Address with a python dictionary inside it.

    How can I get just the python dictionary inside it instead?

    opened by filipeteles 5
  • Support for product count operation

    Support for product count operation

    I ended up not using this (and therefore not testing it thoroughly), but I think this takes care of the product counts unless I'm missing something.

    Submitting for your consideration.

    Regards!

    opened by sebaacuna 5
  • Filter and Pagination

    Filter and Pagination

    I was working on this API for a friend, who later told me about this project after I was almost finished. After taking a look, I noticed that iterating over more than 250 resources and filtering were not supported. Please pull if you like where I am heading with this project. Support for updating and creating will be coming soon.

    Thanks,

    opened by jtallieu 5
  • Library is not documented on Bigcommerce Developer Portal

    Library is not documented on Bigcommerce Developer Portal

    Expected behavior

    should be documented at https://developer.bigcommerce.com/ as per https://github.com/bigcommerce/bigcommerce-api-python#further-documentation

    Actual behavior

    no documentation

    Steps to reproduce behavior

    go to https://developer.bigcommerce.com/ there is no documentation for this library.

    opened by sabotagebeats 4
  • Helper method for creating an authorize URL

    Helper method for creating an authorize URL

    Would be nice to have a method that generates the authorize URL

    Also, the developer site doesn't document what the authorize URL is. I had to guess what it is:

    https://login.bigcommerce.com/oauth2/authorize
    
    opened by dasevilla 4
  • Add high level class layer to API

    Add high level class layer to API

    This adds a new layer to the API on top of @bc-jackiehuynh's existing work. The new class-based layer is heavily inspired by the excellent Stripe API (stripe/stripe-python), and in the process we end up melding a lot of Jackie's work with several ideas from the old version of the API.

    Basic examples of usage are available in the README and examples directory. Test coverage is currently very poor, but will improve over time.

    Ping @maetl

    opened by tgsergeant 4
  • Using v3 Catalog/Product filters

    Using v3 Catalog/Product filters

    Expected behavior

    I'm trying to use the v3 Products API's, but I need to filter by "id:not_in". As far as I know, Python does not allow colons in variable names. So what is the work-around to this?

    I expect that all the filters using a colon will not work.

    # v3 products
    include_fields = "sku, price"
    sort = "sku"
    id:not_in = "689"
    endpoint = '/catalog/products'
    response = api.get(endpoint, include_fields=include_fields, id:not_in=id:not_in, limit=5, page=1, sort=sort)
    

    The expected result would be a list of products where the IDs are not in the list of IDs.

    Actual behavior

    id:not_in = "689" NameError: name 'not_in' is not defined

    Steps to reproduce behavior

    Use above filter to reproduce.

    opened by joegarcia 0
  • Zip payment method not returning in API

    Zip payment method not returning in API

    Expected behavior

    Zip should be returned as a payment method in the PaymentMethods API resource when it is enabled.

    Actual behavior

    Zip is not returned as a payment method.

    Steps to reproduce behavior

    1. Enable Zip as a payment method in the store
    2. Connect to API and run api.PaymentMethods.all()
    3. Zip is not returned as one of the enabled payment methods
    opened by emilian 0
  • Getting subresources alongside products (not separately)

    Getting subresources alongside products (not separately)

    The API supports getting subresources within the same request as products:

    image

    However, the client seems to only provide access one at a time via a separate API call.

    image

    There's no way to just request products and subresources in one call?

    opened by dsoprea 1
  • Old releases, broken functions, V3 support

    Old releases, broken functions, V3 support

    The README.md suggests that api.Products.iterall() and api.Products.count() should exist but they do not appear to.

    Also, the releases page says that the last release was 2019. They're haven't been any substantial updates since then?

    Also, the forum entry at https://github.com/bigcommerce/bigcommerce-api-python/issues/59 says the following:

    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.
    

    Has V3 been since released?

    Lastly, when I call (api).Products.all() for some page equal-to-or-greater-than the page-count (the page after the last page of results), I get a single string with a value of "_connection" back. So, when there are products, we get a Product. Otherwise, we get a string with "_connection". I would expect an empty result or, at worst, a None. Can you explain what's going on here? How is pagination supposed to work? I'm having issues finding documentation and what little documentation is available (above) seems broken or inaccurate. Since the source-code is reflective, there are no clues there, either.

    opened by dsoprea 1
  • Is there a way to update products in batches (more than 1 at a time)?

    Is there a way to update products in batches (more than 1 at a time)?

    Currently, I'm using the following to update information about a single product.

    api.Products.get(1234).update(inventory_level=20)

    Is there a way to update multiple products? I've tried something like this, but got a 404 error.

    api.Products.get([123, 456]).update(inventory_level=20)

    ERROR: 404 Not Found @ products/[123,456]: b'[{"status":404,"message":"The requested resource was not found."}]'

    BigCommerce allow 10 product updates at a time, so I'm trying to see if that is possible. https://developer.bigcommerce.com/api-reference/catalog/catalog-api/products/updateproducts

    opened by HaiSycamore 1
  • Updating customer password gives random 400 errors

    Updating customer password gives random 400 errors

    Overview

    I am trying to update the customer password in one of my applications. Sample code:

    import bigcommerce
    
    big_commerce_url_info = xxx
    big_commerce_store_hash = xxx
    big_commerce_client_id = xxx
    big_commerce_auth_token = xxx
    customer_id = xxx
    password = xxx
    
    try:
        api = bigcommerce.api.BigcommerceApi(client_id=big_commerce_client_id, store_hash=big_commerce_store_hash, access_token=big_commerce_auth_token)
        api.Customers.get(customer_id).update(_authentication=dict(password=password))
    except Exception as e:
        print("ERROR: ", str(e))
    

    Expected behavior

    It should update the password every single time.

    Actual behavior

    It updates the password most of the times for most customers but some times it randomly gives the following error:

    ERROR: 400 Bad Request @ customers/1705: b'[{"status":400,"message":"The field \'password\' is invalid."}]'
    

    Steps to reproduce the behavior

    Just run the code multiple times and it will randomly fail at some point.

    opened by akshatbjain 4
Releases(bigcommerce-0.22.2)
A python based Telegram Bot for Compressing Videos with negligible Quality change

𝕍𝕚𝕕𝕖𝕠 ℂ𝕆𝕄ℙℝ𝔼𝕊𝕊𝕆ℝ 𝔹𝕆𝕋 ᴍᴜʟᴛɪғᴜɴᴄᴛɪᴏɴ ǫᴜᴀʟɪᴛʏ ᴄᴏᴍᴘʀᴇssᴏʀ A Telegram Video CompressorBot it compress videos with negligible Quality change.

Danish 154 Dec 04, 2022
Retrieves GitHub Stats via `git_api` and flask.

GitHub User Search Created using Python3 and git_api, coded by JBYT27. About This is a project I decided to make for Kajam, but I decided to choose a

an aspirin 4 May 11, 2022
Simple script to ban bots at Twitch chats using a text file as a source.

AUTOBAN 🇺🇸 English version Simple script to ban bots at Twitch chats using a text file as a source. How to use Windows Go to releases for further in

And Paiva 5 Feb 06, 2022
Univerity-student oriented (lithuanian) discord bot

Univerity-student oriented (lithuanian) discord bot

3 Nov 30, 2021
Elkeid HUB - A rule/event processing engine maintained by the Elkeid Team that supports streaming/offline data processing

Elkeid HUB - A rule/event processing engine maintained by the Elkeid Team that supports streaming/offline data processing

Bytedance Inc. 61 Dec 29, 2022
Python SDK for interacting with the Frame.io API.

python-frameio-client Frame.io Frame.io is a cloud-based collaboration hub that allows video professionals to share files, comment on clips real-time,

Frame.io 37 Dec 21, 2022
Python API for British Geological Survey magnetic field calculator

Magnetic field calculator Python API for British Geological Survey magnetic field calculator. Description This project magnetic field calculator. It u

Filip Š 3 Mar 11, 2022
Upbit(업비트) Cryptocurrency Exchange OPEN API Client for Python

Base Repository Python Upbit Client Repository Upbit OPEN API Client @Author: uJhin @GitHub: https://github.com/uJhin/upbit-client/ @Officia

Yu Jhin 37 Nov 06, 2022
Example of Telegram local API and aiogram 3.x

Telegram Local Full example of Telegram local application. Contains Telegram Bot API Local Telegram Bot API server based on aiogram Bot API Server ima

Oleg A. 9 Sep 16, 2022
Simple-nft-tutorial - A simple tutorial on making nft/memecoins on algorand

nft/memecoin Tutorial on Algorand Let's make a simple NFT/memecoin on the Algora

2 Feb 05, 2022
Discord Bot that leverages the idea of nested containers using podman, runs untrusted user input, executes Quantum Circuits, allows users to refer to the Qiskit Documentation, and provides the ability to search questions on the Quantum Computing StackExchange.

Discord Bot that leverages the idea of nested containers using podman, runs untrusted user input, executes Quantum Circuits, allows users to refer to the Qiskit Documentation, and provides the abilit

Mehul 23 Oct 18, 2022
A Discord bot written in Python that can be used to control event management on a server.

Event Management Discord Bot A Discord bot written in Python that can be used to control event management on a Discord server. Made originally for GDS

Suvaditya Mukherjee 2 Dec 07, 2021
Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features! 🥰

CallMusicPlus69 This Repo base on! 🤗️ A CallsMusic Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features

brut✘⁶⁹ // ユスフ 6 Jun 26, 2022
Remedy when Amazon ECR is not running basic scans for container CVEs.

Welcome to your CDK Python project! This is a blank project for Python development with CDK. The cdk.json file tells the CDK Toolkit how to execute yo

4n6ir 4 Nov 05, 2022
A Telegram Message Manager Bot by @AbirHasan2005

Messages-Manager-Bot A Telegram Message Manager Bot by @AbirHasan2005. This Bot can delete specific type of messages from Group. I specially use for @

Abir Hasan 32 Nov 12, 2022
My Discord Bot that I used to learn Python. Please disregard the unstructured code!

Botsche My personal Discord Bot. To run this bot, change TOKEN in config.ini to your Discord Bot Token, which can be retrieved from your Discord Dev

Mats Voss 1 Nov 29, 2021
OpenSource bot for control groups ...

⭕️ کمک به افراد برای اداره هرچه فان تره گروه 📟 همه گروه های بزرگ نیاز به یه بات خفن دارن تا از گروه مراقبت کنه این بات کارش همینه سعی کرده فیچر خیلی

Mehran Alam Beigi 2 Nov 26, 2021
Simple software that can send WhatsApp message to a single or multiple users (including unsaved number**)

wp-automation Info: this is a simple automation software that sends WhatsApp message to single or multiple users. Key feature: -Sends message to multi

3 Jan 31, 2022
Crud-python-sqlite: used to manage telephone contacts through python and sqlite

crud-python-sqlite This program is used to manage telephone contacts through python and sqlite. Dependencicas python3 sqlite3 Installation Clone the r

Luis Negrón 0 Jan 24, 2022