woocommerce / woocommerce-rest-api-js-lib

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

Post not work as expected #90

Closed rogerthedeveloper closed 2 years ago

rogerthedeveloper commented 3 years ago

const W = require("@woocommerce/woocommerce-rest-api").default;

const wooAPI = new W({ url: "URL", consumerKey: "...", consumerSecret: "...", version: "wc/v3", wpAPI: true, queryStringAuth: true });

let data = {...}

wooAPI.post("orders", data) .then(response => { // Successful request console.log("Respuesta:", response.data); }) .catch(error => { // Invalid request, for 4xx and 5xx statuses console.log("Response Status:", error.response.status); console.log("Response Headers:", error.response.headers); console.log("Response Data:", error.response.data); });

always return a list of orders instead create new order, its very broken this part, its not useful.

anoblet commented 2 years ago

Did you ever find a solution to this?

rogerthedeveloper commented 2 years ago

async function doWoo(data: any) {

return wooAPI.post("orders", data)
.then((resp: any) => {
    return resp.data;
})
.catch((error: any) => {
    return [];
});

}

rogerthedeveloper commented 2 years ago

async function noteWoo(orderID: any, data: any) {

return wooAPI.post(`orders/${orderID}/notes`, {"note": data})
.then((resp: any) => {
    return resp.data;
})
.catch((error: any) => {
    return [];
});

}