How to add multiple option variant to existing product ?

Tourist
6 0 4

Hi folks,

I need to delete previous product variant from the existing product and add new variant using API. I am facing issue while adding multiple variant to an existing product. Below is the code what I am trying
$access_token = 'xxxxxxxxx';
$curl_url = 'https://example.myshopify.com/admin/api/2019-04/products/3856519725165/variants.json?access_token='....;
$variant = array( "variant" => array(

   'option1' => 'Small',
   'option2' => 'Black',
   'price' => 20
  )
);
I am getting following error.
"Option values provided for 1 unknown option(s)".

Thanks
Deepak
0 Likes
New Member
7 0 0

Hey, 
I am also facing same problem in my API , any solution to this ???

0 Likes
Tourist
6 0 4

Hey @bajwa_rajat ,
You need to remove all the previous variant using API and then add new variants. This is the way I achieved.

0 Likes
New Member
7 0 0

@iamdeepakbasnal  , I have used another aproach . I have updated the product using PUT api of product and send array of all varinats and it worked. But now I am facing a problem, all varinats created in PUT request have inventory 0 , I want to set any parameter in my request which disable inventory tracking for new created varinats. IS this possible ?
Or any alternate solution ?

0 Likes
Shopify Partner
15 1 2

@bajwa_rajat 
Creating a variant with 
"inventory_policy": "continue" 
will allow a product to continue to be sold even after the inventory dips below 0.
Alternatively, creating a variant where 
"inventory_management"=>nil will tell Shopify that the inventory doesn't need to be tracked.

check in this Variant API Doc as well.

1 Like
New Member
7 0 0

Thanks @Muhammad_Asfar  , It worked.
But now I have another case . I want to set inventory quantity of varinats , using Product PUT api. How to achieve this ?

0 Likes