wc-api-php: WooCommerce Rest API Client Library with PHP , localhost GET is not working
Input: index.php
<?php
require __DIR__ . '/vendor/autoload.php';
use Automattic\WooCommerce\Client;
$woocommerce = new Client(
'https://babaplant.com',
'ck_##############',
'cs_##############',
[
'wp_api' => true,
'version' => 'wc/v1',
'query_string_auth' => true,
'verify_ssl' => false
]
);
print_r($woocommerce->get(''));
?>
Output: api framework.zip
“Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: Syntax error in C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php:336 Stack trace: #0 C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php(375): Automattic\WooCommerce\HttpClient\HttpClient->processResponse() #1 C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request(‘’, ‘GET’, Array, Array) #2 C:\xampp\htdocs\index.php(17): Automattic\WooCommerce\Client->get(‘’) #3 {main} thrown in C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php on line 336”
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (5 by maintainers)
for Reference try yourself: http://incals.in/api
*temp purpose… webpage no longer will be available
thanx
And here the real error message:
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException
Some error on your store, so is throwing exceptions and you are catching anything…
Here an example catching exceptions: https://github.com/woocommerce/wc-api-php#response
i am getting results but seems not like in Proper JSON format;
Array ( [0] => Array ( [id] => 15 [name] => Logo T-shirt [slug] => logo-t-shirt [permalink] => http://incals.in/product/logo-t-shirt/ [date_created] => 2016-11-23T11:28:27 [date_modified] => 2016-11-23T11:28:28 [type] => simple [status] => publish [featured] => [catalog_visibility] => visible [description] => This is a sample product description.
[short_description] => This is a short description.
[sku] => [price] => 18 [regular_price] => 20 [sale_price] => 18 [date_on_sale_from] => [date_on_sale_to] => [price_html] => $20.00 $18.00 [on_sale] => 1 [purchasable] => 1 [total_sales] => 0 [virtual] => [downloadable] => [downloads] => Array ( ) [download_limit] => -1 [download_expiry] => -1 [download_type] => standard [external_url] => [button_text] => [tax_status] => taxable [tax_class] => [manage_stock] => 1 [stock_quantity] => 5 [in_stock] => 1 [backorders] => no [backorders_allowed] => [backordered] => [sold_individually] => [weight] => [dimensions] => Array ( [length] => [width] => [height] => ) [shipping_required] => 1 [shipping_taxable] => 1 [shipping_class] => [shipping_class_id] => 0 [reviews_allowed] => 1 [average_rating] => 4.00 [rating_count] => 1 [related_ids] => Array ( [0] => 50 [1] => 37 [2] => 34 ) [upsell_ids] => Array ( [0] => 60 ) [cross_sell_ids] => Array ( ) [parent_id] => 0 [purchase_note] => [categories] => Array ( [0] => Array ( [id] => 9 [name] => Clothing [slug] => clothing ) [1] => Array ( [id] => 14 [name] => T-shirts [slug] => t-shirts ) ) [tags] => Array ( ) [images] => Array ( [0] => Array ( [id] => 172 [date_created] => 2016-11-23T11:28:27 [date_modified] => 2016-11-23T11:28:28 [src] => http://incals.in/wp-content/uploads/2016/11/logo_tee_front.jpg [name] => Logo T-shirt [alt] => [position] => 0 ) [1] => Array ( [id] => 172 [date_created] => 2016-11-23T11:28:27 [date_modified] => 2016-11-23T11:28:28 [src] => http://incals.in/wp-content/uploads/2016/11/logo_tee_front.jpg [name] => Logo T-shirt [alt] => [position] => 1 ) [2] => Array ( [id] => 173 [date_created] => 2016-11-23T11:28:27 [date_modified] => 2016-11-23T11:28:28 [src] => http://incals.in/wp-content/uploads/2016/11/logo_tee_back.jpg [name] => Logo T-shirt [alt] => [position] => 2 ) ) [attributes] => Array ( ) [default_attributes] => Array ( ) [variations] => Array ( ) [grouped_products] => Array ( ) [menu_order] => 0 [_links] => Array ( [self] => Array ( [0] => Array ( [href] => http://incals.in/wp-json/wc/v1/products/15 ) ) [collection] => Array ( [0] => Array ( [href] => http://incals.in/wp-json/wc/v1/products ) ) ) ) [1] => Array ( [id] => 34 [name] => Ninja T-shirt [slug] => ninja-t-shirt [permalink] => http://incals.in/product/ninja-t-shirt/ [date_created] => 2016-11-23T11:28:27 [date_modified] => 2016-11-23T11:28:28 [type] => simple [status] => publish [featured] => [catalog_visibility] => visible [description] => This is a sample product description.
[short_description] => This is a short description. . . .
what kind of JSON it is ? even i hv tried these too http://json-schema.org/example1.html www.jsoneditoronline.org/ & got nothing but ERRORS
*https://url; cause this previous error… now changed to http://url; & ‘verify_ssl’ => false"
then we have-
Fatal error: Uncaught Automattic\WooCommerce\HttpClient\HttpClientException: Error: Invalid timestamp. [woocommerce_rest_authentication_error] in C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php:320 Stack trace: #0 C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php(339): Automattic\WooCommerce\HttpClient\HttpClient->lookForErrors(Array) #1 C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php(375): Automattic\WooCommerce\HttpClient\HttpClient->processResponse() #2 C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\Client.php(82): Automattic\WooCommerce\HttpClient\HttpClient->request(‘’, ‘GET’, Array, Array) #3 C:\xampp\htdocs\index.php(18): Automattic\WooCommerce\Client->get(‘’) #4 {main} thrown in C:\xampp\htdocs\vendor\automattic\woocommerce\src\WooCommerce\HttpClient\HttpClient.php on line 320
It should work with localhost - try disable all plugins besides WC and switch to default theme.
Likely an issue on your store - check the store’s error logs to see.