'WooCommerce Rest API gives syntax error
I'm working on a side project and I've been trying to interact with the WooCommerce REST API.
I have everything seemingly correct. I've created the proper keys because they work with cURL. But when I try to utilize the php-wrapper, provided by Automattic, everything stops working.
I have the code set up exactly like they've instructed: require DIR . '/../vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'https://mywebsitenamegoeshere.com',
'##########',
'##########',
[
'wp_api' => true,
'version' => 'wc/v2',
'query_string_auth' => true
]
);
I'm simply trying to do a request to list the endpoints (which also works with cURL) but as soon as I attempt to interact via the php-wrapper I get this error message:
Fatal error: Uncaught exception 'Automattic\WooCommerce\HttpClient\HttpClientException' with message 'Syntax error' in /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php:346
Stack trace: #0 /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php(385): Automattic\WooCommerce\HttpClient\HttpClient->processResponse()
#1 /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request('', 'GET', Array, Array)
#2 /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/ticket-data-test-template.php(15): Automattic\WooCommerce\Client->get('')
#3 /nas/content/live/wwitssltest/wp-includes/template-loader.php(74): include('/nas/content/li...')
#4 /nas/content/live/wwitssltest/wp-blog-header.php(19): require_once('/nas/content/li...')
#5 /nas/content in /nas/content/live/wwitssltest/wp-content/themes/twentyseventeen/vendor/automattic/woocommerce/src/WooCommerce/HttpClient/HttpClient.php on line 346
When I look in the files, specifically HttpClient.php the most specific information I can come across is that the JSON might not be formatted properly?
The documentation seems pretty cut and dry but nothing I do makes any difference.
With the exception of <php print_r( $woocommerce ); ?> which returns the Client object.
Solution 1:[1]
You're missing a comma after query_string_auth' => true.
It should be: query_string_auth' => true.
Cheers!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ouflak |
