I’m using the PHP client described here: https://github.com/woocommerce/wc-api-php
A client has a third party EPOS which we poll every 10 minutes for stock updates, price updates etc. so I built a Laravel application to consume those changes, format them in a way that’s friendly to the Woo API and then make requests using the PHP client wrapper to put/post those changes.
It’s difficult to give you a full request really because I’ve used my own wrapper class, but the idea is simple:
$this->client = new Client(
config('woocommerce.url'),
config('woocommerce.key'),
config('woocommerce.secret'),
[
'wc_api' => true,
'version' => 'wc/v3'
]
);
This is inside the constructor of the class, setting a private variable for use across all methods:
$response = collect($this->client->put("products/$productId/variations/$variationId", $data));
This is inside a method called “updateProductVariation”:
$data = [
"stock_quantity" => $CrossoverStockLevel['StockLevel']
];
$Woocommerce->updateProductVariation($WoocommerceProduct->id, $WoocommerceVariation->id, $data);
This is the request to that method (I grab IDs by SKU prior to making this request which works fine). The only bit that intermittently fails is the update, even though the syntax is the same every time.