4

I want to get orders details from woocommerce using REST API. If, I tried anything, it returns error like following: {"code":"woocommerce_rest_cannot_view","message":"Sorry, you cannot view this resource.","data":{"status":401}}

I have tried following,

require __DIR__ . '/vendor/autoload.php';

use Automattic\WooCommerce\Client;
use Automattic\WooCommerce\HttpClient\HttpClientException;

$woocommerce = new Client(
'https://www.domain.com', 
'ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxXXXX', 
'cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    [
        'version' => 'v3',
    ]
);

print_r($woocommerce->get('orders'));

So, Please provide any suggestion or idea to acheive this solution. Thanks in advance.

Gugan Abu
  • 546
  • 1
  • 4
  • 17

1 Answers1

0

HTTPS requests require Basic authentication (username and password), but HTTP requests require oAuth1 (encoding the secret and key).

It's not immediately obvious in the documentation, but my answer to this question gives more details "cannot list resources" error from WooCommerce REST API

Essentially, you need to change the secret and key to a base64 encoded "username:password" string (with the "Bearer" prefix) when using HTTPS.

KolonUK
  • 443
  • 1
  • 6
  • 14