Update existing product with no options (variants) to have options (variants)?

Solved
Ron21
Shopify Partner
19 0 3

Hi,

Using REST API...

How would l go about updating an existing product (with no options/variants) to have options/variants? I realize that every product (with no options) has the one variant.

1. Would I need to remove this original/single variant before adding the other variants for options?

2. Should I just add the new options variants, then remove the first/original variant?

3. Or must I update the original variant with an option, then create the other variants?

A final question is:  With an existing product, can I add several variants in one call (like I can with creating a product)?

thanks,
Ron

0 Likes
GrahamS
Shopify Staff
Shopify Staff
83 16 16

Hey @Ron21 !

1 - This isn't necessary. All products need to have at least 1 default variant, so you wouldn't be able to remove that before adding others. Edit - see next post for clarity

2 - You can do that if it's easier for you compared to option 3.

3 - This and option 2 are equally viable from my perspective.

Ultimately, you're going to need to do an assortment of calls here - one to add your new variants, and one to either delete your existing first variant or update it to be in line with the others, whatever is easier for your workflow. As far as adding several variants goes, yes you can do this in a single call. You would just need to perform this call and add a new array for each variant you are creating.

Graham S | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Ron21
Shopify Partner
19 0 3

Thank you , much appreciate you help.

>>> perform this call and add a new array for each variant you are creating

Sorry for my ignorance, not quite sure how to create "arrays" for json. Is it something like this (I get error: expected Array to be a Hash)?

{
  "variant"
  [
  {"option1""Red","price""1.00""requires_shipping"false},
  {"option1""Blue","price""1.00""requires_shipping"false}
  ]
}

 

0 Likes
GrahamS
Shopify Staff
Shopify Staff
83 16 16

This is an accepted solution.

Hello @Ron21 ,

I actually have to walk that one back slightly. It's definitely possible, but you need to hit the product endpoint rather than the variant endpoint.

Firstly, you would perform a "PUT" request against your product ID. From there you would include a variant array that includes the complete list of variants that you wish to have associated with the product. The biggest benefit here is that you actually only need to perform 1 call rather than 2 - because the array will completely replace the existing list of variants, you now no longer need to update or delete the existing default variant. Example:

PUT https://{{ store }}.myshopify.com/admin/api/2021-04/products/12345678910.json

{
	"product":{
	"variants":[
		{
"price": "99.00",
"position": 1,
"inventory_policy": "deny",
"fulfillment_service": "manual",
"option1": "Pink",
"taxable": true,
"requires_shipping": true
		},
		{
"price": "99.00",
"position": 2,
"inventory_policy": "deny",
"fulfillment_service": "manual",
"option1": "Purple",
"taxable": true,
"requires_shipping": true
		}
		]
		}
}

 

This results in my default variant being deleted and replaced with the 2 in this call.

Hope this helps!

Graham S | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Ron21
Shopify Partner
19 0 3

Thanks @GrahamS

Awesome! That'll make it easy to upgrade an existing product to have options.

Ron