Create product with multiple variants having 2 options via API.

Highlighted
New Member
1 0 1

Hi Everyone, I hope somebody can help me with this one.

I have to create a product with multiple variants having 2 options (size,Color). Here is my code 

$products_array = array(
"product"=>array(
"title"=> "Test Product",
"body_html"=> "<strong>Test Product Creation!<\/strong>",
"vendor"=> "Vendor",
"product_type"=> "Test",
"published"=> false,
"variants"=>array(
array(
"sku"=>"100001-100001-c12-L",
"price"=>20.00,
"required_shipping" => true,
"option1" => "L",
"option2"=>"Red"
),
array(
"sku"=>"100001-100001-c14-S",
"price"=>20.00,
"required_shipping" => true,
"option1" => "Small",
"option2" => "Green"
)),
"options"=>array(
"Size","Color" )
)
);

And getting this error message
{"errors":{"options":["is invalid"],"name":["can't be blank"]}}

Can anyone please help me to create a product with multiple variants.
 
Thanks in advance 

 

1 Like