3

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...

Tom
  • 87
  • 1
  • 9
  • Don't you need to also add a domain name into the request url? From example above it looks like you've missed it `axios.put('https://staging/wp-json/wc/v3/orders/1977/consumer_key=123&consumer_secret=456', {status: "completed"});` – Anton Bakinowsky Sep 25 '20 at 15:52
  • yeah, i did that, to make it short, i just put "staging" only here... – Tom Sep 25 '20 at 15:55

1 Answers1

1

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

Shoejep
  • 4,414
  • 4
  • 22
  • 26
  • Thanks for the answer, actually that 123 and 456 represents fake keys, in my original request i use right keys but it fails with 404 – Tom Sep 25 '20 at 15:57
  • A 404 indicates that the url is wrong. Are you sure you've 1. added the domain to the url 2. removed the credentials from the url and 3. made sure that an order exists for that id? – Shoejep Sep 25 '20 at 16:40
  • yeah, the order exists for the id and i am giving the credentials inside the url for other GET requests, and those requests are working fine.... – Tom Sep 25 '20 at 16:44
  • @ Shoejep, Thanks for your answer, it worked. I have separated the keys from url as you have said and put the content type in header. Thanks a lot. – Tom Sep 25 '20 at 22:59