arash rad
arash rad

Reputation: 11

WooCommerce API authorization not working in node.js app

I'm trying to create an app using WooCommerce API.

index.js:

var WooCommerceAPI = require('woocommerce-api');
// var WPAPI = require('wpapi');
var querystring = require('querystring');

var WooCommerce = new WooCommerceAPI({
  url: 'http://shop3.adinweb.ir',
  consumerKey: 'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  consumerSecret: 'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
  wpAPI: true,
  version: 'wc/v2',
  queryStringAuth: true
});

WooCommerce.get('products?page=1', function(err, data, res) {
  console.log(err);
  console.log(res);
});

The result:

result

I'm sure the consumerKey and consumerSecret are correct. I have tried many times :|

Please guide me. What's wrong here?

Upvotes: 1

Views: 491

Answers (2)

Andreas Oikon
Andreas Oikon

Reputation: 65

I am using the woocommerce package and it works fine with 2 changes.

  1. Instead of "consumerSecret", use plain "secret"
  2. In the "apiPath", use "/wp-json/wc/v2"

With these 2 changes the plain "woocommerce" package works like a charm.

Upvotes: 0

Monde Nyawose
Monde Nyawose

Reputation: 11

You logging out the wrong thing I suppose? Should be:

console.log(data)

You must log out the data and not the response.

Upvotes: 1

Related Questions