This is a node.js promisification wrapper for WooCommerce API. Easily interact with the WooCommerce REST API, without worrying about the URLs to use or URL formatting.
npm install --save woo-promise
Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woothemes.com/document/woocommerce-rest-api/.
Get familiar with the endpoints for WooCommerce - so you know what to work with in http://woothemes.github.io/woocommerce-rest-api-docs/.
Once the object is instantiated, you need to call init()
. This will dynamically build the functions for woocommerce, categorising them by group.
There is also the same get()
, post()
, put()
, and delete()
from the base library - only promisified to remove the callback options (info)
var WooPromise = require('woo-promise');
var woopromise = new WooPromise({
url: 'http://example.com',
consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
});
woopromise.init() //this loads the library and tests the connection to WooCommerce
.then(client => {
//do things.
})
.catch(err => {
//error handling
})
The options mirror the ones on WooCommerce API, with a little extra gravy.
Option | Type | Required | Description |
---|---|---|---|
flatten |
Bool |
no | If the library should automatically flatten subelements of the response. Defaults to true . |
The flatten
option removes the top level node from the WooCommerce JSON response. This is something i like to do because I feel like it's just redundant.
All methods return a Promise
either resolving to the output from the API call, or rejecting with an error.
The endpoint
argument is required.
Performs a GET
against the specified endpoint on the WooCommerce instance.
The endpoint
and data
arguments are required.
Performs a POST
against the specified endpoint on the WooCommerce instance, with a body of the data.
The endpoint
and data
arguments are required.
Performs a PUT
against the specified endpoint on the WooCommerce instance, with a body of the data.
The endpoint
argument is required.
Performs a DELETE
against the specified endpoint on the WooCommerce instance.
This is where the gravy arrives.
NOTE: If you require filters on any of the endpoints, you need to specify all arguments as a string. eg:
client.orders.get({filter:{status:'processing'}})
-
client.getInfo()
Returns the base API information for the WooCommerce site. WooCommerce Docs
-
client.coupons.get()
Returns the list of coupons in the system. WooCommerce Docs
-
client.coupons.post(data)
Create coupons. WooCommerce Docs
-
client.coupons.get(id)
View coupon information for
id
. WooCommerce Docs -
client.coupons.put(id, data)
Updated coupon
id
with informationdata
. WooCommerce Docs -
client.coupons.del(id)
Delete coupon
id
. WooCommerce Docs -
client.coupons.count()
Count the number of coupons. WooCommerce Docs
-
client.coupons.bulk.post(data)
Create/Update Multiple Coupons. WooCommerce Docs
-
client.customers.get()
List all customers. WooCommerce Docs
-
client.customers.post(data)
Create a customer. WooCommerce Docs
-
client.customers.get(id)
-
client.customers.email.get(email)
Get specific customer information. WooCommerce Docs
-
client.customers.put(id, data)
Update a customer. WooCommerce Docs
-
client.customers.bulk.post(data)
Create/Update multiple customers. WooCommerce Docs
-
client.customers.del(id)
Delete a customer. WooCommerce Docs
-
client.customers.orders.get(id)
List orders for a customer. WooCommerce Docs
-
client.customers.downloads.get(id)
List downloads for a customer. WooCommerce Docs
-
client.customers.count()
Count the number of customers. WooCommerce Docs
-
client.orders.post(data)
Create order. WooCommerce Docs
-
client.orders.get(id)
View an order. WooCommerce Docs
-
client.orders.get()
Get list of orders. WooCommerce Docs
-
client.orders.put(id, data)
Update an order. WooCommerce Docs
-
client.orders.bulk.post(data)
Create/Update multiple orders. WooCommerce Docs
-
client.orders.del(id)
Delete an order. WooCommerce Docs
-
client.orders.count()
The order count. WooCommerce Docs
-
client.orders.statuses.get()
Get all order statuses. WooCommerce Docs
client.orders.notes.post(order_id, data)
Create a note on order id
. WooCommerce Docs
client.orders.notes.get(order_id, note_id)
View order note. WooCommerce Docs
client.orders.notes.get(order_id)
View all notes on an order. WooCommerce Docs
client.orders.notes.put(order_id, note_id, data)
Update a note. WooCommerce Docs
client.orders.notes.del(order_id, note_id)
Delete a note. WooCommerce Docs
client.orders.refunds.post(order_id)
Create a refund for an order. WooCommerce Docs
client.orders.refunds.get(order_id, refund_id)
View a refund for a given order. WooCommerce Docs
client.orders.refunds.get(order_id)
View all refunds on an order. WooCommerce Docs
client.orders.refunds.put(order_id, refund_id, data)
Update a given refund. WooCommerce Docs
client.orders.refunds.del(order_id, refund_id)
Delete a refund. WooCommerce Docs
- Finish writing the documentation :)