Skip to content

A promisified wrapper for WooCommerce-API, with some nice helpers along the way.

Notifications You must be signed in to change notification settings

fabacus/node-woo-promise

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

dependency status npm version

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

Customers

Orders

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 :)

About

A promisified wrapper for WooCommerce-API, with some nice helpers along the way.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published