Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Axios Put request gives 404 error in Vue.js

I am performing Axios put request to change the status of an order through Woocommerce REST API. I tried different patterns but I am getting 404 error. This is my request

axios.put('https://staging/wp-json/wc/v3/orders/1977/consumer_key=123&consumer_secret=456', 
{status: "completed"});

I tried this also

axios.put('https://staging/wp-json/wc/v3/orders/1977/consumer_key=123&consumer_secret=456/"Content-Type: application/json"', 
{status: "completed"});

This is from API documentation

curl -X PUT https://example.com/wp-json/wc/v3/orders/727 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
  "status": "completed"
}'

Where am I doing wrong? Any suggestions please...

like image 461
Tom Avatar asked Nov 18 '25 10:11

Tom


1 Answers

I'm not an expert, but it looks like -u in curl is for authentication.

cUrls's option “-u”

Assuming it's Basic authentication, I would try the below.

You'll have to replace "123" and "456" with your credentials.

axios.put('https://staging/wp-json/wc/v3/orders/1977', 
{
    status: "completed"
},
{
    headers: {
        Authorization: "Basic " + btoa("123" + ":" + "456")
    }
});

You should make sure that you've:

  1. Added the domain to the url

  2. Removed the credentials from the url

  3. Made sure an order exists for that id

like image 149
Shoejep Avatar answered Nov 20 '25 22:11

Shoejep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!