Getting in an exception for get product detail by id in woocommerce REST api

Question

I need to create an order in woocommerce REST API

I have tried following code

require('../wp-blog-header.php'); 

header("HTTP/1.1 200 OK"); 
header("Status: 200 All rosy");

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

use AutomatticWooCommerceClient;

// Local Server
$woocommerce = new Client(
    'https://exmapledomain.com/', 
    'key1', 
    'key2',
    [
        'wp_api' => true,
        'timeout' => 45000,
        'version' => 'wc/v3',
    ]
);

print_r($woocommerce->get('products/803'));exit;

I am getting error like below

2020-10-07T11:38:40+05:30 CRITICAL Uncaught AutomatticWooCommerceHttpClientHttpClientException: Error: Sorry, you cannot view this resource. [woocommerce_rest_cannot_view] in /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php:324
Stack trace:

#0 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php(349): AutomatticWooCommerceHttpClientHttpClient->lookForErrors(Array)

#1 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php(385): AutomatticWooCommerceHttpClientHttpClient->processResponse()

#2 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/Client.php(82): AutomatticWooCommerceHttpClientHttpClient->request(‘products/803’, ‘GET’, Array, Array)

#3 /opt/bitnami/apps/wordpress/htdocs/app/orderApi.php(38): AutomatticWooCommerceClient->get(‘products/803’)

#4 {main}
thrown in /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php on line 324

tech versions
1.PHP version:7.3.18
2.wordpress:4.5.2
3.woocommerce:5.5.1
4.REST api package :4.5.2

0
Pranav Patel 4 months 0 Answers 9 views 0

Leave an answer