php-shopify
php-shopify copied to clipboard
Cannot create new variant
Shopify Api reference
Create a new product variant
POST /admin/products/#{product_id}/variants.json { "variant": { "option1": "Yellow", "price": "1.00" } }
With this PHP Code:
$newVariant = array(
"option1" => "black",
"price" => "20.00"
);
$shopify->Product($product_id)->Variant->post($newVariant);
I recive this error:
Fatal error: Uncaught PHPShopify\Exception\CurlException: Request failed with HTTP Code 406.
@salvobunetto It seems like you have error in config part. Please post your config code.
@tareqtms I'm getting the exactly same problem...
My code:
$config = array(
'ShopUrl' => $this->shop_url,
'ApiKey' => $this->api_key,
'Password' => $this->password
);
ShopifySDK::config($config);
$shopify = new ShopifySDK($config);
$putArray = array('option1' => 'Yellow', 'price' => '1.00');
$shopify->ProductVariant(999999999999)->post($putArray);
Result: Request failed with HTTP Code 406
@tareqtms i figured out what im doing wrong...
$putArray = array('option1' => 'Yellow', 'price' => '1.00');
$shopify->Product(4368899801181)->Variant->post($putArray);
That works perfectly... @salvobunetto