Can't add new variant to existing product

Highlighted
Not applicable
1393 0 0

API Key: c0b17bcf44c89916ad57cb4254f8e4b4

Hello

I have an existing product in Shopify and want to be able to add additional variants. I am PUTting the following JSON object (see below). The last variant has id:"" as it is a new variant being added (I have also tried this with id:"" removed.)

The response I get back is:

{"errors":{"variants":["Variants have not been changed. The following IDs do not exist or do not belong to the product: [\"\", \"\"]"]}}

 So, How do I add a new variant to an existing product?

{"product":{
	"body_html":"Pin on badge to celebrate 1 year attendance.\r\nOne Supplied.",
	"created_at":"\/Date(-62135596800000)\/",
	"handle":"GBA00601",
	"images":null,
	"options":[
		{
			"name":"Years attended"
		}
	],
	"product_type":"Books",
	"published_at":"2015-03-20T13:55:31Z",
	"published_scope":"global",
	"tags":"Restricted",
	"template_suffix":null,
	"title":"ATTENDANCE AWARD",
	"updated_at":"\/Date(-62135596800000)\/",
	"variants":[
		{
			"barcode":null,
			"compare_at_price":null,
			"created_at":"\/Date(-62135596800000)\/",
			"fulfillment_service":"manual",
			"grams":0,
			"inventory_management":"shopify",
			"inventory_policy":"deny",
			"inventory_quantity":215.00000,
			"metafield":null,
			"option1":"1",
			"option2":null,
			"option3":null,
			"position":null,
			"price":1.10000,
			"product_id":"465959475",
			"requires_shipping":true,
			"sku":"GBA00601",
			"taxable":true,
			"title":null,
			"updated_at":"\/Date(-62135596800000)\/",
			"id":"1235677479"
		},
		{
			"barcode":null,
			"compare_at_price":null,
			"created_at":"\/Date(-62135596800000)\/",
			"fulfillment_service":"manual","grams":0,
			"inventory_management":"shopify",
			"inventory_policy":"deny",
			"inventory_quantity":202.00000,
			"metafield":null,
			"option1":"2",
			"option2":null,
			"option3":null,
			"position":null,
			"price":1.10000,
			"product_id":"465959475",
			"requires_shipping":true,
			"sku":"GBA00602",
			"taxable":true,
			"title":null,
			"updated_at":"\/Date(-62135596800000)\/",
			"id":"1235677483"
		},
		{
			"barcode":null,
			"compare_at_price":null,
			"created_at":"\/Date(-62135596800000)\/",
			"fulfillment_service":"manual",
			"grams":0,
			"inventory_management":"shopify",
			"inventory_policy":"deny",
			"inventory_quantity":214.00000,
			"metafield":null,
			"option1":"3",
			"option2":null,
			"option3":null,
			"position":null,
			"price":1.10000,
			"product_id":"465959475",
			"requires_shipping":true,
			"sku":"GBA00603",
			"taxable":true,
			"title":null,
			"updated_at":"\/Date(-62135596800000)\/",
			"id":"1235677487"
		},
		{
			"barcode":null,
			"compare_at_price":null,
			"created_at":"\/Date(-62135596800000)\/",
			"fulfillment_service":"manual",
			"grams":0,"inventory_management":"shopify",
			"inventory_policy":"deny",
			"inventory_quantity":227.00000,
			"metafield":null,
			"option1":"4",
			"option2":null,
			"option3":null,
			"position":null,
			"price":1.10000,
			"product_id":"465959475",
			"requires_shipping":true,
			"sku":"GBA00604",
			"taxable":true,
			"title":null,
			"updated_at":"\/Date(-62135596800000)\/",
			"id":""
		},
		{
			"barcode":null,
			"compare_at_price":null,
			"created_at":"\/Date(-62135596800000)\/",
			"fulfillment_service":"manual",
			"grams":0,
			"inventory_management":"shopify",
			"inventory_policy":"deny",
			"inventory_quantity":200.00000,
			"metafield":null,
			"option1":"5",
			"option2":null,
			"option3":null,
			"position":null,
			"price":1.10000,
			"product_id":"465959475",
			"requires_shipping":true,
			"sku":"GBA00605",
			"taxable":true,
			"title":null,
			"updated_at":"\/Date(-62135596800000)\/",
			"id":""
		}
	],
	"vendor":null,
	"id":"465959475"
}}

Thanks

Geoff

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
157 0 14

If you remove the "id" property entirely from any new variants, it shouldn't give you that error.

Note that any variants left out of the list will be removed from the product.

You also have the option of doing a POST to the /admin/variants.json endpoint to create new variants one at a time.

James MacAulay, Shopify Developer
0 Likes
Highlighted
Not applicable
1393 0 0

Many thanks for your help!

I thought I had tried it without the id:"" bits. After two days away I retried it and it works.

Thanks again

Geoff

0 Likes
Highlighted
New Member
1 0 0

This has happened to us a couple times.  Once we just waited a few seconds (I'm assuming for the pictures to load or something) and clicked save, and it worked.  This last time, we were duplicating an existing item, and it had different variants than the original item.  The issue was that we were able to rename the variants on the main page, so we did that, but that's what caused the issue.  Instead, we had to go to the Variants section and hover over 'more options', then click 'edit options'.  We had to add new ones, and erase the old ones, and then saving it worked fine.

0 Likes