woocommerce / woocommerce-rest-api-js-lib

New JavaScript library for WooCommerce REST API
https://www.npmjs.com/package/@woocommerce/woocommerce-rest-api
MIT License
286 stars 75 forks source link

post delete put function success but it did not add delete or change product #95

Open markhsiaowork opened 3 years ago

markhsiaowork commented 3 years ago

post delete put function success but it did not add delete or change product

So I am trying to add a product to my woo-commerce shop using the woocommerce-rest-api. I can successfully retrieve a list of the products using the WooCommerce.get("products") method, but when I used the post method to add a new product. It successfully give me a response (showing the list of products) but it did not add the new product.

//CONFIG
const WooCommerceRestApi = require("@woocommerce/woocommerce-rest-api").default;
const WooCommerce = new WooCommerceRestApi({
  url: "https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.com",
  consumerKey: "ck_xxxxxxxxxxxxxxxxxxxxxxxxxxx",
  consumerSecret: "cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  version: "wc/v3",
  queryStringAuth: true,
});
//NEW PRODUCT

const data = {
  name: "Premium Quality", // See more in https://woocommerce.github.io/woocommerce-rest-api-docs/#product-properties
  type: "simple",
  regular_price: "21.99",
};
//POST
WooCommerce.post("products", data)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.log(error.response.data);
  });
anoblet commented 3 years ago

Did you ever find a solution to this?

markhsiaowork commented 3 years ago

Yeah, so the problem is inside my config where url: "https://example.com. I just put a https://(www).example.com and it worked.

Because when I submit a post request I point it to the URL example.com which will get redirect to the actual address www.example.com and every time it redirects it will change to Get request.