Problem with retrieving order via REST API
-
I’m trying to retrieve an order using this code:
<?php require '/home/username/vendor/autoload.php'; use Automattic\WooCommerce\Client; use Automattic\WooCommerce\HttpClient\HttpClientException; $wc = new Client( 'https://www.website.com/wp', 'ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [ 'wp_api' => true, 'version' => 'wc/v1', 'query_string_auth' => true, ] ); try { $results = $wc->get("orders/418"); print_r($results); } catch (HttpClientException $e) { echo $e->getMessage() . "\n\n"; echo print_r($e->getRequest(), true) . "\n\n"; echo print_r($e->getResponse()) . "\n\n"; } ?>This is the output:
Syntax error Automattic\WooCommerce\HttpClient\Request Object ( [url:Automattic\WooCommerce\HttpClient\Request:private] => https://www.website.com/wp/wp-json/wc/v1/orders/418?consumer_key=ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&consumer_secret=cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [method:Automattic\WooCommerce\HttpClient\Request:private] => GET [parameters:Automattic\WooCommerce\HttpClient\Request:private] => Array ( [consumer_key] => ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [consumer_secret] => cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ) [headers:Automattic\WooCommerce\HttpClient\Request:private] => Array ( [Accept] => application/json [Content-Type] => application/json [User-Agent] => WooCommerce API Client-PHP/1.1.1 ) [body:Automattic\WooCommerce\HttpClient\Request:private] => ) Automattic\WooCommerce\HttpClient\Response Object ( [code:Automattic\WooCommerce\HttpClient\Response:private] => 200 [headers:Automattic\WooCommerce\HttpClient\Response:private] => Array ( [Server] => nginx [Date] => Fri, 08 Jul 2016 09:44:28 GMT [Content-Type] => application/json; charset=UTF-8 [Transfer-Encoding] => chunked [Connection] => keep-alive [X-Content-Type-Options] => nosniff [Access-Control-Expose-Headers] => X-WP-Total, X-WP-TotalPages [Access-Control-Allow-Headers] => Authorization [Expires] => Wed, 11 Jan 1984 05:00:00 GMT [Cache-Control] => no-cache, must-revalidate, max-age=0 [Pragma] => no-cache [Last-Modified] => Thu, 01 Jan 1970 00:00:00 GMT [Host-Header] => 192fc2e7e50945beb8231a492d6a8024 [X-Proxy-Cache] => MISS ) [body:Automattic\WooCommerce\HttpClient\Response:private] => <br /> <b>Notice</b>: Undefined variable: post in <b>/home/username/public_html/wp/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-rest-posts-controller.php</b> on line <b>141</b><br /> <br /> <b>Notice</b>: Trying to get property of non-object in <b>/home/username/public_html/wp/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-rest-posts-controller.php</b> on line <b>141</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/username/public_html/wp/wp-content/plugins/woocommerce/includes/abstracts/abstract-wc-rest-posts-controller.php:141) in <b>/home/username/public_html/wp/wp-includes/rest-api/class-wp-rest-server.php</b> on line <b>1196</b><br /> {"code":"woocommerce_rest_invalid_shop_order_id","message":"Invalid id.","data":{"status":404}} ) 1The order id is definetely valid, I can see it when I list all orders with $wc->get(“orders”). I’ve tried retrieving customers and product in an analogous way and it worked fine.
Am I doing something wrong?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Problem with retrieving order via REST API’ is closed to new replies.