I\'m trying to connect to the WooCommerce API using Guzzle 5 (Guzzle 6 seems not has oAuth options o.O). Woocommerce requires the oAuth authentication method to work.
<
Now the plugin OauthSubscriber
is available only for Guzzle 6.
Testing around again, I've found the bug: it is in the method signUsingHmacSha1()
that anyway adds an umpersand (&) to the string to sign and this causes the error from WooCommerce.
I've opened a issue on GitHub and sent a pull request to fix the bug.
The correct way to connect to the WooCommerce API V2 using Guzzle 6 (once the bug is fixed! Take care of the version of the WooCommerce API you connect: the API v3 still doesn't work!) is this:
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\Subscriber\Oauth\Oauth1;
$options = array(
// Add the home URL to the store you want to connect to here (without the end / )
'remoteUrl' => 'http://example.com/',
// Add your own Consumer Key here
'remoteConsumerKey' => 'ck_4rdyourConsumerKey8ik',
// Add your own Secret Key here
'remoteSecretKey' => 'cs_738youconsumersecret94i',
// Add the endpoint base path
'remoteApiPath' => 'wc-api/v2/',
);
$remoteApiUrl = $options['remoteUrl'] . $options['remoteApiPath'];
$endpoint = 'orders';
$handler = new CurlHandler();
$stack = HandlerStack::create($handler);
$middleware = new Oauth1([
'consumer_key' => $options['remoteConsumerKey'],
'consumer_secret' => $options['remoteSecretKey'],
'token_secret' => '',
'token' => '',
'request_method' => Oauth1::REQUEST_METHOD_QUERY,
'signature_method' => Oauth1::SIGNATURE_METHOD_HMAC
]);
$stack->push($middleware);
$client = new Client([
'base_uri' => $remoteApiUrl,
'handler' => $stack
]);
$res = $client->get($endpoint, ['auth' => 'oauth');
As told, this connection works only with the version 2 of the WooCommerce API.
I'm investigating to understand why the V3 doesn't work.