woo-promise
v1.1.3
Published
A promise wrapper for the woocommerce api
Downloads
9
Maintainers
Readme
WooPromise - Promisified WooCommerce API Wrapper
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.
Installation
npm install --save woo-promise
Getting Started
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)
Setup
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
})
Options
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.
API
All methods return a Promise
either resolving to the output from the API call, or rejecting with an error.
Basic Methods
client.get(endpoint)
The endpoint
argument is required.
Performs a GET
against the specified endpoint on the WooCommerce instance.
client.post(endpoint, data)
The endpoint
and data
arguments are required.
Performs a POST
against the specified endpoint on the WooCommerce instance, with a body of the data.
client.put(endpoint, 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.
client.delete(endpoint)
The endpoint
argument is required.
Performs a DELETE
against the specified endpoint on the WooCommerce instance.
Magic Methods
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'}})
Global
client.getInfo()
Returns the base API information for the WooCommerce site. WooCommerce Docs
Coupons
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 Docsclient.coupons.put(id, data)
Updated coupon
id
with informationdata
. WooCommerce Docsclient.coupons.del(id)
Delete coupon
id
. WooCommerce Docsclient.coupons.count()
Count the number of coupons. WooCommerce Docs
client.coupons.bulk.post(data)
Create/Update Multiple Coupons. WooCommerce Docs
Customers
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
Orders
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
Order Notes
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
Order Refunds
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
Products
Product Attributes
Product Attribute Terms
Product Categories
Product Shipping Classes
Product Tags
Reports
Taxes
Tax Classes
Webhooks
TODO
- Finish writing the documentation :)