I am able to pull orders, from my shop, with a simple file_get_contents(), but I cant get the automattic/woocommerce php library to work. And by 'work' I mean that it does connect and try to pull the orders, but the store not allowing it. (error: [woocommerce_rest_cannot_view] ). I have been successful pulling orders, with the library, on a different woo install.
Here's my code: (i've played with the options a bit, no luck)
function d($var){var_dump($var);}
$woocommerce = new Client(
"https://{$domain}.com/",
$ckey,
$csec,
array( 'wp_api' => true
,'version' => 'wc/v2'
,'verify_ssl' => false
,'queryStringAuth' => false
)
);
try {
$results = $woocommerce->get('orders');
} catch (HttpClientException $e) {
d( $e->getMessage() );
// Error: Sorry, you cannot list resources. [woocommerce_rest_cannot_view]
d( $e->getRequest()->getUrl() );
// https://example.com/wp-json/wc/v2/orders
d( $e->getRequest()->getparameters() );
// empty array
}
$res = json_decode(file_get_contents("https://{$domain}.com/wp-json/wc/v2/orders?consumer_key={$ckey}&consumer_secret={$csec}&per_page=99"));
d($res );
// works, full list of orders.
After a short look in the documentation you posted in your comments: read the docs! Especially the part about $lastRequest->getBody()
You only do the get request, but dont read the reaponse body.