admin管理员组文章数量:1122832
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 Automattic\WooCommerce\Client;
// Local Server
$woocommerce = new Client(
'/',
'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 Automattic\WooCommerce\HttpClient\HttpClientException: 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): Automattic\WooCommerce\HttpClient\HttpClient->lookForErrors(Array)
#1 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php(385): Automattic\WooCommerce\HttpClient\HttpClient->processResponse()
#2 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request('products/803', 'GET', Array, Array)
#3 /opt/bitnami/apps/wordpress/htdocs/app/orderApi.php(38): Automattic\WooCommerce\Client->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
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 Automattic\WooCommerce\Client;
// 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 Automattic\WooCommerce\HttpClient\HttpClientException: 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): Automattic\WooCommerce\HttpClient\HttpClient->lookForErrors(Array)
#1 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php(385): Automattic\WooCommerce\HttpClient\HttpClient->processResponse()
#2 /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request('products/803', 'GET', Array, Array)
#3 /opt/bitnami/apps/wordpress/htdocs/app/orderApi.php(38): Automattic\WooCommerce\Client->get('products/803')
#4 {main} thrown in /opt/bitnami/apps/wordpress/htdocs/app/src/WooCommerce/HttpClient/HttpClient.php on line 324
Share Improve this question edited Oct 7, 2020 at 6:53 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Oct 7, 2020 at 6:27 Pranav PatelPranav Patel 211 gold badge1 silver badge4 bronze badgestech versions
1.PHP version:7.3.18
2.wordpress:4.5.2
3.woocommerce:5.5.1
4.REST api package :4.5.2
1 Answer
Reset to default 0I have resolve that error by add following line in code.
'query_string_auth' => true
code should be like below
// Local Server
$woocommerce = new Client(
'https://exmapledomain.com/',
'key1',
'key2',
[
'wp_api' => true,
'timeout' => 45000,
'version' => 'wc/v3',
'query_string_auth' => true,
]
);
本文标签: Getting in an exception for get product detail by id in woocommerce REST api
版权声明:本文标题:Getting in an exception for get product detail by id in woocommerce REST api 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300478a1930825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论