We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Updating a product using Guzzle via the API

Updating a product using Guzzle via the API

Rich3
Tourist
7 1 1

Hi

 

I am trying to update a product via the API using Guzzle, and I am getting a '200' response back in the status code and no errors, but the product data is not updating. Am I missing something? Fetching products and fetching individual products works fine, I just don't seem to be able to update them. I have checked the scope which has read and write for products, and with no error back, I'm not sure where else to look... 

 

public function apiUpdateProduct($id, $data) : void
{
$this->validate($data);

if(!empty($this->errors)){
return;
};

$this->token = $_ENV["SHOPIFY_ACCESS_TOKEN"];

$client = new Client([
'base_uri' => "https://xxxxxxx.myshopify.com/admin/api/2024-07/" // commented out the shop id
]);

try {

$response = $client->put("products/{$id}.json", [
"headers" => [
"X-Shopify-Access-Token" => $this->token,
"Content-Type" => "application/json"
],
"json" => [
"product" => $data
]
]);

$statusCode = $response->getStatusCode();
$body = $response->getBody();
$responseBody = json_decode($body->__toString(), true);

if ($statusCode == 200) {

$product = $responseBody["product"];

$this->product = [
"id" => $product['id'],
"title" => $product['title'],
"body_html" => $product['body_html']
];

} else {

$this->addError("API", 'Failed to update product: ' . $statusCode);

}

} catch (GuzzleHttp\Exception\ClientException $e) {
echo 'Client error: ' . $e->getMessage();
} catch (GuzzleHttp\Exception\ServerException $e) {
echo 'Server error: ' . $e->getMessage();
} catch (GuzzleHttp\Exception\RequestException $e) {
echo 'Request error: ' . $e->getMessage();
}

}
Reply 1 (1)

WaliedKhalid
Visitor
1 0 0

 

2am facing here the same problem using Guzzel is there any lead, how to use shopify api call with guzzel ?