|
| 1 | +# WooCommerce API - Python Client |
1 | 2 |
|
2 |
| -# woocommerce-api |
| 3 | +A Python wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library. |
3 | 4 |
|
4 |
| -A Python wrapper for the WooCommerce REST API |
| 5 | +[](http://travis-ci.org/woothemes/wc-api-python) |
5 | 6 |
|
6 |
| -## README |
| 7 | +## Installation |
7 | 8 |
|
8 |
| -This is the README file for woocommerce-api |
| 9 | +``` |
| 10 | +pip install woocommerce |
| 11 | +``` |
9 | 12 |
|
10 |
| -There are many like it, but this one is mine. |
| 13 | +## Getting started |
11 | 14 |
|
12 |
| -## Todo |
| 15 | +Generate API credentials (Consumer Key & Consumer Secret) following this instructions <http://docs.woothemes.com/document/woocommerce-rest-api/> |
| 16 | +. |
13 | 17 |
|
14 |
| -[ ] Update README file with something useful about the project |
15 |
| -[ ] Write code |
16 |
| -[ ] Ship code |
17 |
| -[ ] Profit! |
| 18 | +Check out the WooCommerce API endpoints and data that can be manipulated in <http://woothemes.github.io/woocommerce-rest-api-docs/>. |
| 19 | + |
| 20 | +## Setup |
| 21 | + |
| 22 | +```py |
| 23 | +from woocommerce import WooCommerce |
| 24 | + |
| 25 | +var WooCommerce = new WooCommerceAPI({ |
| 26 | + url: 'http://example.com', |
| 27 | + consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', |
| 28 | + consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' |
| 29 | +}); |
| 30 | +``` |
| 31 | + |
| 32 | +### Options |
| 33 | + |
| 34 | +| Option | Type | Required | Description | |
| 35 | +| ---------------- | -------- | -------- | --------------------------------------------------------------------------------------------------- | |
| 36 | +| `url` | `string` | yes | Your Store URL, example: http://woo.dev/ | |
| 37 | +| `consumerKey` | `string` | yes | Your API consumer key | |
| 38 | +| `consumerSecret` | `string` | yes | Your API consumer secret | |
| 39 | +| `version` | `string` | no | API version, default is `v3` | |
| 40 | +| `verify_ssl` | `bool` | no | Verify SSL when connect, use this option as `false` when need to test with self-signed certificates | |
| 41 | + |
| 42 | +## Methods |
| 43 | + |
| 44 | +| Params | Type | Description | |
| 45 | +| ---------- | ------------ | ------------------------------------------------------------ | |
| 46 | +| `endpoint` | `string` | WooCommerce API endpoint, example: `customers` or `order/12` | |
| 47 | +| `data` | `dictionary` | Data that will be converted to JSON | |
| 48 | + |
| 49 | +### GET |
| 50 | + |
| 51 | +- `.get(endpoint)` |
| 52 | + |
| 53 | +### POST |
| 54 | + |
| 55 | +- `.post(endpoint, data)` |
| 56 | + |
| 57 | +### PUT |
| 58 | + |
| 59 | +- `.put(endpoint, data)` |
| 60 | + |
| 61 | +### DELETE |
| 62 | + |
| 63 | +- `.delete(endpoint)` |
| 64 | + |
| 65 | +## Response |
| 66 | + |
| 67 | +All methods will return [Requests](http://docs.python-requests.org/en/latest/) object. |
| 68 | + |
| 69 | +Example of returned data: |
| 70 | + |
| 71 | +```bash |
| 72 | +>>> woocommerce.get("products") |
| 73 | +>>> woocommerce.status_code |
| 74 | +200 |
| 75 | +>>> woocommerce.headers['content-type'] |
| 76 | +'application/json; charset=UTF-8' |
| 77 | +>>> woocommerce.encoding |
| 78 | +'UTF-8' |
| 79 | +>>> woocommerce.text |
| 80 | +u'{"products":[{"title":"Flying Ninja","id":70,...' // Json text |
| 81 | +>>> woocommerce.json() |
| 82 | +{u'products': [{u'sold_individually': False,... // Dictionary data |
| 83 | +``` |
0 commit comments