NodeJS WooCommerce product post error 400

I have been trying to insert a product using nodejs woocommerce api (v3) with the code below. However, the code only works when I remove the marked section. Otherwise I get the error code 400.

var WooCommerce = require('woocommerce');

var wooCommerce = new WooCommerce({
  url: 'http://mysite',
  consumerKey: 'ck_XXXXXX',
  secret: 'cs_XXXXXX'
});

var data = {
  product: {
    title: 'Premium Quality',
    type: 'simple',
    regular_price: '21.99',
    description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
    short_description: 'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
    categories: [
      9,
      14
    ]     
    //################ WORKS WHEN THIS SECTION IS REMOVED ##############
    ,
    images: [
      {
        src: 'http://example.com/wp-content/uploads/2015/01/premium-quality-front.jpg',
        position: 0
      },
      {
        src: 'http://example.com/wp-content/uploads/2015/01/premium-quality-back.jpg',
        position: 1
      }
    ]
    //###################################################################
  }
};

wooCommerce.post('/products', data, function(err, data, res) {
  console.log(res);
});

How can I add images to the product along with this API call? Thanks in advance!

Read more here: NodeJS WooCommerce product post error 400

Leave a Reply

Your email address will not be published. Required fields are marked *