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 simple python script that monitors the binance hotwallet and refunds the withdrawal fee to encourage people to withdraw their Nano and help decentralisation

Nano_Binance_Refund_Bot a simple python script that monitors the binance hotwallet and refunds the withdrawal fee to encourage people to withdraw thei

James Coxon 5 Apr 07, 2022
Video-Player - Telegram Music/ Video Streaming Bot Using Pytgcalls

Video Player 🔥 ᴢᴀɪᴅ ᴠᴄ ᴘʟᴀyᴇʀ ɪꜱ ᴀ ᴛᴇʟᴇɢʀᴀᴍ ᴘʀᴏᴊᴇᴄᴛ ʙᴀꜱᴇᴅ ᴏɴ ᴘʏʀᴏɢʀᴀᴍ ꜰᴏʀ ᴘʟᴀʏ

Zaid 16 Nov 30, 2022
Python lib for Embedly

embedly-python Python library for interacting with Embedly's API. To get started sign up for a key at embed.ly/signup. Install Install with Pip (recom

Embedly 80 Oct 05, 2022
REPO USERBOT YANG DIBUAT DARI BERBAGAI REPO USERBOT GITHUB.

Lord Userbot Userbot Yang Digunakan Untuk Bersenang-Senang Di Telegram Repo Lord Userbot Repo Yang Dibuat Alvin Dari Berbagai Repo Userbot Github CARA

Alvin 70 Jan 02, 2023
🤖 Chegg answers requested and sent by the Discord BOT to the targeted user.

Chegg BOT Description "I believe that open-source resources are a must for everyone around. Especially in the field of education. As Chegg c

Vusal Ismayilov 33 Aug 20, 2021
A Simple Telegram Inline Torrent Search Bot by @infotechIT

Torrent-Search-RoBot A Simple Telegram Inline Torrent Search Bot by @infotechIT. Torrent API Using api.infotech.wtf API Host Bot Deploy to Heroku Clic

InfoTech 0 May 05, 2022
AminoSpamKilla - Spam bot for amino that uses multiprocessing module

AminoSpamKilla Spam bot for amino that uses multiprocessing module Pydroid Open

4 Jun 27, 2022
Python SDK for IEX Cloud

iexfinance Python SDK for IEX Cloud. Architecture mirrors that of the IEX Cloud API (and its documentation). An easy-to-use toolkit to obtain data for

Addison Lynch 640 Jan 07, 2023
Python client for Toyota North America service API

toyota-na Python client for Toyota North America service API Install pip install toyota-na[qt] [qt] is required for generating authorization code. Us

Gavin Ni 18 Sep 06, 2022
A play store search telegram bot

Play-Store-Bot A play store search telegram bot Made with Python3 (C) @FayasNoushad Copyright permission under MIT License License - https://github.c

Fayas Noushad 17 Oct 28, 2022
An Async Bot/API wrapper for Twitch made in Python.

TwitchIO is an asynchronous Python wrapper around the Twitch API and IRC, with a powerful command extension for creating Twitch Chat Bots. TwitchIO co

TwitchIO 590 Jan 03, 2023
An alternative to OpenFaaS nats-queue-worker for long-running functions

OpenFaas Job Worker OpenFaas Job Worker is a fork of project : OSCAR Worker - https://github.com/grycap/oscar-worker Thanks to Sebástian Risco @srisco

Sebastien Aucouturier 1 Jan 07, 2022
The Simple Google Colab Notebook to Download Files from Direct Link to Google Drive with custom name and bulk link support.

Direct Link to Google Drive (Advanced! 🔥 ) The Most Advanced yet Simple Google Colab Notebook to Download Files from Direct Link to Google Drive. 🆕

Dr.Caduceus 14 Jul 26, 2022
A basic Ubisoft API wrapper created in python.

UbisoftAPI A basic Ubisoft API wrapper created in python. I will be updating this with more endpoints as time goes on. Please note that this is my fir

Ethan 2 Oct 31, 2021
A visualization of people a user follows on Twitter

Twitter-Map This software allows the user to create maps of Twitter accounts. Installation git clone Oliver Greenwood 12 Jul 20, 2022

A Powerful Telethon Based Telegram Spam Bot.

Yukki Multi Spam Bot 🚀 Deploy on Heroku You can Use these API ID and API HASH while deploying String Session No Requirement of API ID and API HASH Ge

46 Dec 23, 2022
数字货币动态趋势网格,随着行情变动。目前实盘月化10%。目前支持币安,未来上线火币、OKEX。

数字货币动态趋势网格,随着行情变动。目前实盘月化10%。目前支持币安,未来上线火币、OKEX。

幸福村的码农 98 Dec 27, 2022
With Google Drive API. My computer and my phone are in love now.

Channel trought Google Drive Google Drive API In this case, "Google Drive App" is the program. To install everything you need(has some extra things),

Luis Quiñones Requelme 1 Dec 15, 2021
Dumps to CSV all the resources in an organization's member accounts

AWS Org Inventory Dumps to CSV all the resources in an organization's member accounts. Set your environment's AWS_PROFILE and AWS_DEFAULT_REGION varia

Iain Samuel McLean Elder 2 Dec 24, 2021
An Advanced Python Playing Card Module that makes creating playing card games simple and easy!

playingcards.py An Advanced Python Playing Card Module that makes creating playing card games simple and easy! Features Easy to Understand Class Objec

Blake Potvin 5 Aug 30, 2022