npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

woo-promise

v1.1.3

Published

A promise wrapper for the woocommerce api

Downloads

9

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.

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