# woo-promise

> A promise wrapper for the woocommerce api

Latest version **1.1.3** (published 2016-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install woo-promise
pnpm add woo-promise
yarn add woo-promise
bun add woo-promise
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2016-07-11 |
| First published | 2016-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Patrick McKinley |
| Maintainers | lilmuckers |
| Keywords | woocommerce, promise, api, ecommerce, payment, order, customers |

## Links

- npm: https://www.npmjs.com/package/woo-promise
- Repository: https://github.com/fabacus/node-woo-promise
- Homepage: https://github.com/fabacus/node-woo-promise#readme
- Issues: https://github.com/fabacus/node-woo-promise/issues
- npm.io page: https://npm.io/package/woo-promise

## Dependencies (4)

- [qs](https://npm.io/package/qs.md) ^6.2.0
- [perry](https://npm.io/package/perry.md) ^0.1.3
- [sprintf-js](https://npm.io/package/sprintf-js.md) ^1.0.3
- [woocommerce-api](https://npm.io/package/woocommerce-api.md) ^1.4.0

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.1.3 (latest) — 2016-07-11
- 1.1.2 — 2016-04-25
- 1.1.1 — 2016-04-25
- 1.1.0 — 2016-04-25
- 1.0.0 — 2016-04-25
- 0.2.0 — 2016-04-23
- 0.1.1 — 2016-04-22
- 0.1.0 — 2016-04-22

## README

# WooPromise - Promisified WooCommerce API Wrapper

This is a node.js promisification wrapper for [WooCommerce API](https://github.com/woothemes/wc-api-node/). Easily interact with the WooCommerce REST API, without worrying about the URLs to use or URL formatting.

[![dependency status](https://david-dm.org/fabacus/node-woo-promise.svg)](https://david-dm.org/fabacus/node-woo-promise)
[![npm version](https://img.shields.io/npm/v/woo-promise.svg)](https://www.npmjs.com/package/woo-promise)

## 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](https://github.com/woothemes/wc-api-node/))

## Setup
```js
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](https://github.com/woothemes/wc-api-node/), 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:
```javascript
  client.orders.get({filter:{status:'processing'}})
```

### Global
  - `client.getInfo()`

    Returns the base API information for the WooCommerce site. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-index-list)

### Coupons
  - `client.coupons.get()`

    Returns the list of coupons in the system. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-coupons)
  - `client.coupons.post(data)`

    Create coupons. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-coupon)
  - `client.coupons.get(id)`

    View coupon information for `id`. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-a-coupon)
  - `client.coupons.put(id, data)`

    Updated coupon `id` with information `data`. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#update-a-coupon)
  - `client.coupons.del(id)`

    Delete coupon `id`. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#delete-a-coupon)
  - `client.coupons.count()`

    Count the number of coupons. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-coupons-count)
  - `client.coupons.bulk.post(data)`

    Create/Update Multiple Coupons. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-update-multiple-coupons)

### Customers
  - `client.customers.get()`

    List all customers. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-customers)
  - `client.customers.post(data)`

    Create a customer. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-customer)
  - `client.customers.get(id)`
  - `client.customers.email.get(email)`

    Get specific customer information. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-a-customer)
  - `client.customers.put(id, data)`

    Update a customer. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#update-a-customer)
  - `client.customers.bulk.post(data)`

    Create/Update multiple customers. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-update-multiple-customers)
  - `client.customers.del(id)`

    Delete a customer. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#delete-a-customer)
  - `client.customers.orders.get(id)`

    List orders for a customer. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-customer-orders)
  - `client.customers.downloads.get(id)`

    List downloads for a customer. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-customer-downloads)
  - `client.customers.count()`

    Count the number of customers. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-customers-count)

### Orders
  - `client.orders.post(data)`

    Create order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-an-order)
  - `client.orders.get(id)`

    View an order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-an-order)
  - `client.orders.get()`

    Get list of orders. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-orders)
  - `client.orders.put(id, data)`

    Update an order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#update-an-order)
  - `client.orders.bulk.post(data)`

    Create/Update multiple orders. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-update-multiple-orders)
  - `client.orders.del(id)`

    Delete an order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#delete-an-order)
  - `client.orders.count()`

    The order count. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-orders-count)
  - `client.orders.statuses.get()`

    Get all order statuses. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-order-statuses)

### Order Notes
  - `client.orders.notes.post(order_id, data)`

  Create a note on order `id`. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-note-for-an-order)
  - `client.orders.notes.get(order_id, note_id)`

  View order note. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-an-order-note)
  - `client.orders.notes.get(order_id)`

  View all notes on an order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-notes-from-an-order)
  - `client.orders.notes.put(order_id, note_id, data)`

  Update a note. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#update-an-order-note)
  - `client.orders.notes.del(order_id, note_id)`

  Delete a note. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#delete-an-order-note)

### Order Refunds
  - `client.orders.refunds.post(order_id)`

  Create a refund for an order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#create-a-refund-for-an-order)
  - `client.orders.refunds.get(order_id, refund_id)`

  View a refund for a given order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-an-order-refund)
  - `client.orders.refunds.get(order_id)`

  View all refunds on an order. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-refunds-from-an-order)
  - `client.orders.refunds.put(order_id, refund_id, data)`

  Update a given refund. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#update-an-order-refund)
  - `client.orders.refunds.del(order_id, refund_id)`

  Delete a refund. [WooCommerce Docs](http://woothemes.github.io/woocommerce-rest-api-docs/#delete-an-order-refund)

### Products

### Product Attributes

### Product Attribute Terms

### Product Categories

### Product Shipping Classes

### Product Tags

### Reports

### Taxes

### Tax Classes

### Webhooks

# TODO
 - Finish writing the documentation :)

---
_Source: https://npm.io/package/woo-promise · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
