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?
To enable the legacy REST API within WooCommerce, go to WooCommerce > Settings > Advanced > Legacy API and tick the Enable the legacy REST API checkbox.
In order to test the WooCommerce REST API, you will need to install and activate the WooCommerce plugin on your WordPress site. Once you have done that, you can create a REST API client in order to make calls to the WooCommerce REST API.
In this article, we will show you how to use WooCommerce REST API in Postman. First, you need to install and activate the WooCommerce REST API plugin. For more information, see our article on how to install a WordPress plugin. Once the plugin is activated, you need to generate an API key.
Authentication Methods
For the newer APIs (not the "legacy" APIs):
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
API login username and password (also "Consumer key is missing" error)
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]
Apache authorization variable
You may need to fill the authorization variable in Apacheif you use FCGId. In your .htaccess or sites sections, add this :
<IfModule mod_fcgid.c>
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
(https://fuelphp.com/forums/discussion/12825/rest-authentication-does-not-work-under-default-cgi-configurations-solution-within/p1)
For future Googlers... I needed to added this to my .htaccess
RewriteRule ^index.php$ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With