-
Notifications
You must be signed in to change notification settings - Fork 214
Open
Description
I am unable to update or add products via the shopify API. I can read products fine, and delete products, but updating or adding will not work.
This is logged CurlException: Request failed with HTTP Code 400.
And this is the output to the screen
Fatal error: Uncaught PHPShopify\Exception\CurlException: Request failed with HTTP Code 400. in /Users/xxxredactedxxxxx/Sites/MCMS/vendor/phpclassic/php-shopify/lib/HttpRequestJson.php:209
When called from the controller, the model class constructor sets up the connection
public function __construct()
{
$config = array(
"ShopUrl" => $_ENV["SHOPIFY_SHOP_URL"],
"AccessToken" => $_ENV["SHOPIFY_ACCESS_TOKEN"],
"Content_type" => "application/json",
"Curl" => array(
CURLOPT_TIMEOUT => 10,
CURLOPT_FOLLOWLOCATION => true
)
);
$this->shopify = new ShopifySDK($config);
}
and then the controller calls an update method
public function apiUpdateProduct($id, $data) : void
{
$this->validate($data);
if(!empty($this->errors)){
return;
};
$data = json_encode($data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
try {
$response = $this->shopify->Product($id)->put($data);
} catch (CurlException $e) {
$this->addError("product", $e->getMessage());
error_log("CurlException: " . $e->getMessage());
} catch (\Exception $e) {
$this->addError("product", $e->getMessage());
error_log("Exception: " . $e->getMessage());
}
}
Metadata
Metadata
Assignees
Labels
No labels