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 method not working properly #76

Open JuanJTorres11 opened 4 years ago

JuanJTorres11 commented 4 years ago

When I make a post request with the JS library, the response that I get is the list of all the elements of the endpoint, as if I would be using a get. I have tried with multiple endpoints and always the result is the same; even with the same example of the ReadMe, the only response that I got is a get of all the products.

If I make the post request in postman or with Axios, it works fine.

freebeans commented 4 years ago

Hey @JuanJTorres11, I've been using the (now deprecated) older woocommerce-api library and I've seen a lot of endpoints returning a list instead of a status after POSTs and PUTs.

Anyway, if you provide a minimal reproducible example I might be able to help you. Remember not to post you API keys though.

JuanJTorres11 commented 4 years ago

Thanks, here is the code that I used

axios.post('${site}/wp-json/wc/v3/orders?consumer_key=${user}&consumer_secret=${password}', data)
        .then(function (response) {
            console.log(response.data);
        })
        .catch(function (error) {
            console.log(error.response.data);
        });

    //   WooCommerce.post("orders", data)
    //     .then((response) => {
    //       console.log(response);
    //     })
    //     .catch((error) => {
    //       console.log(error);
    //     });

data is the object that represents the order that I try to post, using Axios it works fine, but if I try with the woocommerce library that is commented, the response that I get is the same as I would have done a get over all the orders.

rogerthedeveloper commented 3 years ago

Same here its a bug i'm still receiving a list of orders instead a new created one with post method

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

archonitex commented 3 years ago

Still getting this as well here.

Tried to force it using the _request function and passing in 'post' for the request method, but same thing. It executes as a 'GET' request.

Anyone?

archonitex commented 3 years ago

Ok I got lucky and figured it out, looks like my webhost was redirecting my requests to "www" prefix for my domain, and they don't keep the request method so it redirected to a 'GET' Request