Jim
Jim

Reputation: 2828

Woocommerce REST API 401

similar question has been asked before however I am not sure if the proposed solutions can be applied in my case. I have generated consumerKey and consumerSecret as per the woocommerce api documentation. I have confirmed that I can get the results using these keys by calling the below url in the webbrowser:

https://mywebsite.com/wp-json/wc/v2/products?consumer_key=ck_blahblah&consumer_secret=cs_blahblah

However, when I execute the same api call in the postman, using GET and correctly replacing user-> consumerKey and pass -> consumerSecret I always get 401 : woocommerce_rest_cannot_view. I have tried both http and https with the same error. Any ideas?

Upvotes: 1

Views: 5524

Answers (2)

Allan Zeidler
Allan Zeidler

Reputation: 337

Woo Commerce uses a diferent authentication method for HTTP and HTTPS.

So, if "HTTPS" = 1 is not being passed by Apache/Nginx to you code it will enforce the HTTP method.

Do a double check if this "HTTPS" is passed to your PHP:

  1. Open the file: ./wp-includes/load.php
  2. Search for "is_ssl"
  3. Insert a "echo 'test_beg'; echo $_SERVER['HTTPS']; echo 'test_end';
  4. Do a request on the API
  5. If it return test_beg and test_end without "on" or "1" in the middle, the HTTPS is not being passedList item

It can happen when using a reverse proxy, so, you could need to insert "SetEnvIf HTTPS on HTTPS=on" on your httpd.conf (if using Apache).

I hope it helps :)

(remember to delete these 'echo' on load.php)

Upvotes: 1

Ajay Ghaghretiya
Ajay Ghaghretiya

Reputation: 822

Use this plugin https://github.com/WP-API/Basic-Auth and when you call the API use the Basic Authentication using the username and password.

Upvotes: 4

Related Questions