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 🙏

© 2026 – Pkg Stats / Ryan Hefner

woocommerce-rest-api

v1.1.1

Published

Reusable WooCommerce REST API SDK for products, orders, customers, coupons, and store operations.

Readme

woocommerce-rest-api

woocommerce-rest-api is a reusable Node.js SDK for WooCommerce stores. The package is structured into reusable transport, auth, and resource modules so application teams can use it directly in apps or extend it inside their own commerce tooling.

Why this package is useful

  • Modular src/ layout instead of a single monolithic client file
  • Config validation with zod
  • axios transport with consistent response envelopes
  • Automatic auth strategy selection for HTTPS and HTTP deployments
  • Built-in pagination helper for list endpoints
  • Separate resource helpers for catalog, orders, customers, and store operations

Installation

npm install woocommerce-rest-api

Quick start

const WooCommerceRestApi = require('woocommerce-rest-api');

async function main() {
  const api = new WooCommerceRestApi({
    url: 'https://store.example.com',
    consumerKey: process.env.WC_KEY,
    consumerSecret: process.env.WC_SECRET,
    version: 'wc/v3',
    timeout: 15000,
  });

  const products = await api.getProducts({
    per_page: 20,
    status: 'publish',
  });

  console.log(products.data);
  console.log(products.meta.pagination);
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
});

Response format

All request helpers return a consistent envelope:

{
  data,
  statusCode,
  headers,
  meta: {
    pagination: {
      total,
      totalPages
    }
  }
}

That makes it easier to build SDK wrappers, dashboards, background jobs, and internal admin tools without special-casing list responses.

Authentication strategies

authStrategy supports:

  • auto: uses basic for HTTPS and oauth1 for HTTP
  • basic
  • query-string
  • oauth1

Example:

const api = new WooCommerceRestApi({
  url: 'https://store.example.com',
  consumerKey: process.env.WC_KEY,
  consumerSecret: process.env.WC_SECRET,
  authStrategy: 'query-string',
});

Core usage

Products

const created = await api.createProduct({
  name: 'Developer Hoodie',
  type: 'simple',
  regular_price: '59.99',
  manage_stock: true,
  stock_quantity: 25,
});

await api.updateProduct(created.data.id, {
  sale_price: '49.99',
});

await api.deleteProduct(created.data.id, {
  force: true,
});

Orders

const order = await api.createOrder({
  payment_method: 'bacs',
  payment_method_title: 'Direct Bank Transfer',
  set_paid: true,
  billing: {
    first_name: 'Jane',
    last_name: 'Doe',
    email: '[email protected]',
  },
  line_items: [
    { product_id: 42, quantity: 1 },
  ],
});

await api.updateOrder(order.data.id, {
  status: 'completed',
});

Customers and coupons

const customers = await api.getCustomers({ role: 'customer' });

const coupon = await api.createCoupon({
  code: 'WELCOME10',
  discount_type: 'percent',
  amount: '10',
});

await api.updateCoupon(coupon.data.id, {
  amount: '15',
});

Pagination helper

const allProducts = await api.paginate('products', { per_page: 50 }, { maxPages: 5 });

console.log(allProducts.data.length);
console.log(allProducts.pagesFetched);

Generic requests

If your store exposes custom endpoints, use the generic request methods:

const webhooks = await api.get('webhooks');

const extensionData = await api.request('POST', 'my-plugin/v1/sync', {
  data: {
    source: 'inventory-job',
  },
});

API

new WooCommerceRestApi(options)

| Option | Required | Default | Description | | --- | --- | --- | --- | | url | Yes | — | Store base URL | | consumerKey | Yes | — | WooCommerce consumer key | | consumerSecret | Yes | — | WooCommerce consumer secret | | version | No | 'wc/v3' | API version | | verifySsl | No | true | Whether TLS certificates must validate | | timeout | No | 10000 | Request timeout in milliseconds | | authStrategy | No | 'auto' | Auth mode | | userAgent | No | woocommerce-rest-api/1.1.0 | Custom user agent | | headers | No | {} | Default request headers |

Generic methods

  • request(method, endpoint, options?)
  • get(endpoint, options?)
  • post(endpoint, data, options?)
  • put(endpoint, data, options?)
  • delete(endpoint, options?)
  • paginate(endpoint, params?, options?)

Resource methods

  • getProducts(params?)
  • getProduct(id)
  • createProduct(data)
  • updateProduct(id, data)
  • deleteProduct(id, params?)
  • getOrders(params?)
  • getOrder(id)
  • createOrder(data)
  • updateOrder(id, data)
  • deleteOrder(id, params?)
  • getCustomers(params?)
  • getCustomer(id)
  • createCustomer(data)
  • updateCustomer(id, data)
  • getCoupons(params?)
  • getCoupon(id)
  • createCoupon(data)
  • updateCoupon(id, data)
  • deleteCoupon(id, params?)
  • getCategories(params?)
  • getReports(type?)
  • getSystemStatus()
  • getShippingZones()

Error handling

const { WooCommerceRestApiError } = require('woocommerce-rest-api');

try {
  await api.getProduct(999999);
} catch (error) {
  if (error instanceof WooCommerceRestApiError) {
    console.error(error.statusCode);
    console.error(error.body);
    console.error(error.request);
  }
}

License

This package is licensed under the MIT License. See LICENSE.