Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
WooCommerceAPI
✓ const WooCommerceAPI = require('woocommerce-api');
✗ import WooCommerceAPI from 'woocommerce-api';
This package is CommonJS-only. ESM import syntax will not work directly and requires a CommonJS wrapper or bundler configuration.
This code demonstrates how to initialize the `woocommerce-api` client and fetch a list of products from a WooCommerce store using the modern WP REST API.
const WooCommerceAPI = require('woocommerce-api');
// IMPORTANT: This library is obsolete and no longer maintained.
// Consider migrating to '@woocommerce/woocommerce-rest-api' for active support.
const consumerKey = process.env.WOO_CONSUMER_KEY ?? 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const consumerSecret = process.env.WOO_CONSUMER_SECRET ?? 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
const storeUrl = process.env.WOO_STORE_URL ?? 'http://your-woocommerce-store.com'; // Replace with your store URL
// Configure the client for WooCommerce 2.6+ using the WP REST API
const WooCommerce = new WooCommerceAPI({
url: storeUrl,
consumerKey: consumerKey,
consumerSecret: consumerSecret,
wpAPI: true, // Set to true for modern WooCommerce API
version: 'wc/v1', // API version (e.g., 'wc/v1', 'wc/v2', 'wc/v3')
verifySsl: process.env.NODE_ENV === 'production' // Only verify SSL in production
});
// Example: Fetch a list of products
WooCommerce.get('products', function(err, data, res) {
if (err) {
console.error('API Error:', err.message);
// data might contain raw error response from WooCommerce
if (data) console.error('Raw error data:', data.toString());
return;
}
try {
const products = JSON.parse(res);
console.log(`Successfully retrieved ${products.length} products.`);
if (products.length > 0) {
console.log('First product name:', products[0].name);
console.log('First product price:', products[0].regular_price);
}
} catch (parseError) {
console.error('Failed to parse response:', parseError.message);
console.error('Raw response:', res);
}
});
Errors
Common errors & fixes
Error: self signed certificate in certificate chain
Attempting to connect to a WooCommerce instance with a self-signed SSL certificate without disabling SSL verification.
fixFor development or testing with self-signed certificates, set the `verifySsl` option to `false` in the client configuration (e.g., `verifySsl: false`). Do not use this in production.
Request failed with status code 401: Consumer Key and Consumer Secret are required.
Incorrect or missing API consumer key/secret, or the provided keys do not have sufficient permissions to access the requested resources.
fixEnsure `consumerKey` and `consumerSecret` are correctly configured in your client options. Verify that the keys generated in your WooCommerce store have 'Read/Write' permissions for the actions you are performing.
Request failed with status code 404: No route was found matching the URL and request method
The configured `url` or `version` is incorrect, or the requested API endpoint path does not exist on the WooCommerce store.
fixDouble-check the `url` to your WooCommerce store, the `version` (`wc/v1` for modern, `v3` for legacy), and ensure `wpAPI: true` is set for WooCommerce 2.6+ when using `wc/v1`.
Audit
Dependencies
No dependency data recorded yet.