"cannot list resources" error from WooCommerce REST API

DD77 picture DD77 · Mar 4, 2017 · Viewed 20k times · Source

I am very new to WordPres` and using the WooCommerce plugin for the first time and want to use the WooCommerce REST API in my Android app.

I have enabled the REST API and created a Consumer Key as well as a Consumer secret.

Now, when am using this url http://www.my-domain.com/wp-json/wc/v1/products/ in my browser to check if the API is working or not, I get this error:

{"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot list resources.","data":{"status":401}}

SSL is not installed on my server. How can I fix this? Do I need to use the PHP Client Library?

Answer

KolonUK picture KolonUK · Jul 6, 2018

For the "new" v2 API (not the "legacy v2" API):

  • For secure connections (HTTPS), you need to use "Basic Authentication".
  • For non-secure connections (HTTP), you need to use "oAuth1 Authentication".

If you use the wrong authentication with the wrong connection, you'll get the 401 response message.

This is covered in the WooCommerce API documentation: https://woocommerce.github.io/woocommerce-rest-api-docs/#authentication-over-https

Also note that normally you would pass the CK and CS in as header fields, but depending on how the server is configured, you may find that it will not parse the header fields correctly, so you may get success if you include the CK and CS in the URL as parameters:

https://website.tld/wp-json/wc/v1/products?consumer_key=[key]&consumer_secret=[secret]