Question: How to update the price of a woocommerce product via API using Guzzle and guzzle/oauth-subscriber
I've used This Question as my reference to get oauth1 working for requesting data, which works well. Just haven't been able to workout out to send post variables.
Most tutorials and the guzzle docs use the $client->request('GET', 'http://httpbin.org', [ 'query' => ['foo' => 'bar'] ]);
but that isn't working either:
$response = $client->request('POST', $endpoint, [
'auth' => 'oauth',
'form_params' => [
'price' => '21'
]
]);
This is my current code, with the get $client->get()
commented out what successfully returns a product.
$endpoint = 'products/12';
$handler = new \GuzzleHttp\Handler\CurlHandler();
$stack = \GuzzleHttp\HandlerStack::create($handler);
$middleware = new \GuzzleHttp\Subscriber\Oauth\Oauth1([
'consumer_key' => $this->consumer_key,
'consumer_secret' => $this->consumer_secret,
'token_secret' => '',
'token' => '',
'request_method' => Oauth1::REQUEST_METHOD_QUERY,
'signature_method' => Oauth1::SIGNATURE_METHOD_HMAC
]);
$stack->push($middleware);
$client = new \GuzzleHttp\Client([
'base_uri' => $this->url . $this->api,
'handler' => $stack
]);
$response = $client->post( $endpoint, [ 'auth' => 'oauth' ], ['price' => '21'] );
var_dump($response);
//$response = $client->get( $endpoint, [ 'auth' => 'oauth' ] );
//return array(
// 'status' => $response->getStatusCode(),
// 'header' => $response->getHeaderLine('content-type'),
// 'body' => json_decode($response->getBody())
//);