php-shopify icon indicating copy to clipboard operation
php-shopify copied to clipboard

Cannot create new variant

Open salvobunetto opened this issue 6 years ago • 3 comments

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 avatar Feb 07 '19 21:02 salvobunetto

@salvobunetto It seems like you have error in config part. Please post your config code.

tareqtms avatar May 22 '19 14:05 tareqtms

@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

NettoPassaro avatar Nov 11 '19 21:11 NettoPassaro

@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

NettoPassaro avatar Nov 11 '19 22:11 NettoPassaro