Skip to content

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

Open
@markhsiaowork

Description

@markhsiaowork

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);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions