Fun fact: if you’re trying to use the WooCommerce REST API on localhost:80
while developing, you’ll run into a 401 error pretty much immediately:
HTTP/1.1 401 Unauthorized
{
"code": "woocommerce_rest_cannot_view",
"message": "Sorry, you cannot list resources.",
"data": {
"status": 401
}
}
What you want to do first is get an auth token and secret from your WooCommerce backend: WooCommerce > Settings > Advanced > REST API
Once you’re done this, you can follow this rather smart solution with an authorization header or, if you just need read access to the API, you can do it the quick and slightly dirty way and just add this to your local wp-config.php
:
if ( isset( $_GET['consumer_key'] ) && isset( $_GET['consumer_secret'] ) ) {
$_SERVER['HTTPS'] = 'on';
}