|
| 1 | +Bigcommerce API Python Client |
| 2 | +================================== |
| 3 | + |
| 4 | +|Build Status| |Package Version| |Downloads| |
| 5 | + |
| 6 | +Wrapper over the ``requests`` library for communicating with the Bigcommerce v2 API. |
| 7 | + |
| 8 | +Install with ``pip install bigcommerce`` or ``easy_install bigcommerce``. Tested with |
| 9 | +python 2.7 and 3.4, and only requires ``requests`` and ``streql``. |
| 10 | + |
| 11 | +Usage |
| 12 | +----- |
| 13 | + |
| 14 | +Connecting |
| 15 | +~~~~~~~~~~ |
| 16 | + |
| 17 | +.. code:: python |
| 18 | +
|
| 19 | + import bigcommerce |
| 20 | +
|
| 21 | + # Public apps (OAuth) |
| 22 | + # Access_token is optional, if you don't have one you can use oauth_fetch_token (see below) |
| 23 | + api = bigcommerce.api.BigcommerceApi(client_id='', store_hash='', access_token='') |
| 24 | +
|
| 25 | + # Private apps (Basic Auth) |
| 26 | + api = bigcommerce.api.BigcommerceApi(host='store.mybigcommerce.com', basic_auth=('username', 'api token')) |
| 27 | +
|
| 28 | +``BigcommerceApi`` also provides two helper methods for connection with OAuth2: |
| 29 | + |
| 30 | +- ``api.oauth_fetch_token(client_secret, code, context, scope, redirect_uri)`` |
| 31 | + -- fetches and returns an access token for your application. As a |
| 32 | + side effect, configures ``api`` to be ready for use. |
| 33 | + |
| 34 | +- ``BigcommerceApi.oauth_verify_payload(signed_payload, client_secret)`` |
| 35 | + -- Returns user data from a signed payload. |
| 36 | + |
| 37 | +Accessing and objects |
| 38 | +~~~~~~~~~~~~~~~~~~~~~ |
| 39 | + |
| 40 | +The ``api`` object provides access to each API resource, each of which |
| 41 | +provides CRUD operations, depending on capabilities of the resource: |
| 42 | + |
| 43 | +.. code:: python |
| 44 | +
|
| 45 | + api.Products.all() # GET /products |
| 46 | + api.Products.get(1) # GET /products/1 |
| 47 | + api.Products.create(name='', type='', ...) # POST /products |
| 48 | + api.Products.get(1).update(price='199.90') # PUT /products/1 |
| 49 | + api.Products.delete_all() # DELETE /products |
| 50 | + api.Products.get(1).delete() # DELETE /products/1 |
| 51 | + api.Products.count() # GET /products/count |
| 52 | +
|
| 53 | +The client provides full access to subresources, both as independent |
| 54 | +resources: |
| 55 | + |
| 56 | +:: |
| 57 | + |
| 58 | + api.ProductOptions.get(1) # GET /products/1/options |
| 59 | + api.ProductOptions.get(1, 2) # GET /products/1/options/2 |
| 60 | + |
| 61 | +And as helper methods on the parent resoource: |
| 62 | + |
| 63 | +:: |
| 64 | + |
| 65 | + api.Products.get(1).options() # GET /products/1/options |
| 66 | + api.Products.get(1).options(1) # GET /products/1/options/1 |
| 67 | + |
| 68 | +These subresources implement CRUD methods in exactly the same way as |
| 69 | +regular resources: |
| 70 | + |
| 71 | +:: |
| 72 | + |
| 73 | + api.Products.get(1).options(1).delete() |
| 74 | + |
| 75 | +Filters |
| 76 | +~~~~~~~ |
| 77 | + |
| 78 | +Filters can be applied to ``all`` methods as keyword arguments: |
| 79 | + |
| 80 | +.. code:: python |
| 81 | +
|
| 82 | + customer = api.Customers.all(first_name='John', last_name='Smith')[0] |
| 83 | + orders = api.Orders.all(customer_id=customer.id) |
| 84 | +
|
| 85 | +Error handling |
| 86 | +~~~~~~~~~~~~~~ |
| 87 | + |
| 88 | +Minimal validation of data is performed by the client, instead deferring |
| 89 | +this to the server. A ``HttpException`` will be raised for any unusual |
| 90 | +status code: |
| 91 | + |
| 92 | +- 3xx status code: ``RedirectionException`` |
| 93 | +- 4xx status code: ``ClientRequestException`` |
| 94 | +- 5xx status code: ``ServerException`` |
| 95 | + |
| 96 | +The low level API |
| 97 | +~~~~~~~~~~~~~~~~~ |
| 98 | + |
| 99 | +The high level API provided by ``bigcommerce.api.BigcommerceApi`` is a |
| 100 | +wrapper around a lower level api in ``bigcommerce.connection``. This can |
| 101 | +be accessed through ``api.connection``, and provides helper methods for |
| 102 | +get/post/put/delete operations. |
| 103 | + |
| 104 | +Further documentation |
| 105 | +--------------------- |
| 106 | + |
| 107 | +Full documentation of the API is available on the Bigcommerce |
| 108 | +`Developer Portal <http://developer.bigcommerce.com>`__ |
| 109 | + |
| 110 | +To do |
| 111 | +----- |
| 112 | + |
| 113 | +- Automatic enumeration of multiple page responses |
| 114 | + |
| 115 | +.. |Build Status| image:: https://travis-ci.org/bigcommerce/bigcommerce-api-python.png?branch=master |
| 116 | + :target: https://travis-ci.org/bigcommerce/bigcommerce-api-python |
| 117 | +.. |Package Version| image:: https://pypip.in/v/bigcommerce/badge.png |
| 118 | + :target: https://pypi.python.org/pypi/bigcommerce |
| 119 | +.. |Downloads| image:: https://pypip.in/d/bigcommerce/badge.png |
| 120 | + :target: https://pypi.python.org/pypi/bigcommerce |
0 commit comments