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

npm-woocommerce-api

v1.0.7

Published

Connects NodeJS to the WooCommerce API even though permalink doesnt in active state.

Downloads

16

Readme

npm-woocommerce-api

Connects NodeJS to the WooCommerce API even though permalink doesnt in active state.

Speciality of this module

In this npm module we added an option "permalink". It will help you to mention and inform to the wordpress api to provide restfull api with endpoints or non restfull api with endpoints based on "permalink" option. If you set "permalink" as "plain" (that is inactive) in your wordpress website, existing npm modules for woocommerce api wont work. But, npm-woocommerce-api will work perfectly even though you set "permalink" as "plain" in your wordpress website.

Installation

To install the module using NPM:

npm install npm-woocommerce-api --save

Setup

You will need a consumer key and consumer secret to call your store's WooCommerce API. You can find instructions here

Include the 'npm-woocommerce-api' module within your script and instantiate it with a config:

var NPMWooCommerceAPI = require('npm-woocommerce-api');

var NPMWooCommerceAPI = new NPMWooCommerceAPI({
  url: 'https://yourstore.com',
  ssl: true,
  consumerKey: 'ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  secret: 'cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
});

Instantiating a NPMWooCommerceAPI instance without a url, consumerKey or secret will result in an error being thrown

Options

When instantiating the NPMWooCommerceAPI object you have a choice of the following configuration options:

| option | type | required | description | |-------------|---------|----------|-------------------------------------------------------------------------------------------------------------------------------------| | url | string | yes | The url of your store including the protocol: http://yourstore.com, https://yoursecurestore.com | | consumerKey | string | yes | The consumer key generated in the store admin | | secret | string | yes | The consumer secret generated in the store admin | | ssl | boolean | no | (default: based on protocol, https = true, http = false) this is automatically set by default, but can be forced by setting the ssl option | | logLevel | number | no | (default: 0) 0 shows errors only, 1 shows info and errors for debugging | | apiPath | string | no | (default: '/wc-api/v2') The path to your API, it should contain a leading slash and no trailing slash | | permalink | number | no | (default: 1) 1: active, 0: inactive (default: 1). If your store is having permalink as "Plain", you should use this option with the value as 0. Then only, you can get valid response which consists the required data. Because, based on wordpress permalink active state, rest api will work. If wordpress permalink set as "Plain", rest api wont work and woocommerce api will give an error message.

For your reference, kindly see the following screenshot.

This screenshot depicts about "permalink" inactive state.

Wordpress permalink inactive state

Calling the API

Your WooCommerce API can be called once the NPMWooCommerceAPI object has been instantiated (see above).

GET

NPMWooCommerceAPI.get('/products', function(err, data, res){
  // err will return any errors that occur
  // data will contain the body content from the request
  // res is the full response object, use this to get headers etc
});

POST

For this example you have a coupon object.

NPMWooCommerceAPI.post('/coupons', couponObject, function(err, data, res){
  // err will return any errors that occur
  // data will contain the body content from the request
  // res is the full response object, use this to get headers etc
});

PUT

var couponUpdate = {
  amount: 5
};

NPMWooCommerceAPI.put('/coupons/1234', couponUpdate, function(err, data, res){
  // err will return any errors that occur
  // data will contain the body content from the request
  // res is the full response object, use this to get headers etc
});

DELETE

NPMWooCommerceAPI.delete('/coupons/1234', function(err, data, res){
  // err will return any errors that occur
  // data will contain the body content from the request
  // res is the full response object, use this to get headers etc
});

Testing

npm test

License

GPL 3.0