PUT Product API Variant Options Map not working

Tourist
3 0 1

The Problem:

When a product has an options map of 2 possible things it can vary on, when adding a third but maintaining the original two the api will throw a strange error.



Here is a simple example of what I explained above:

    "options":[
    {
    "values":[
    "Agate"
    ],
    "name":"ztone"
    },
    {
    "values":[
    "8.0",
    "10.0",
    "11.0"
    ],
    "name":"Ring size"
    }
    ]

 

being updated to this ->

    "options":[
    {
    "values":[
    "Chocolate",
    "Blue",
    "Two-Tone"
    ],
    "name":"Metal Color"
    },
    {
    "values":[
    "Agate"
    ],
    "name":"ztone"
    },
    {
    "values":[
    "8.0",
    "10.0",
    "11.0"
    ],
    "name":"Ring size"
    }
    ]

The shopify api will return this error

 ShopifyError: [name:[of Option is not unique], options:[is invalid]] 

Other than the fact this is not a useful error, you can almost guess that it is failing on some sort of mapping call and cannot find a key in the existing options map. You can actually go around this and make things work by posting the options map in this order:

    "options":[
    {
    "values":[
    "Agate"
    ],
    "name":"ztone"
    },
    {
    "values":[
    "8.0",
    "10.0",
    "11.0"
    ],
    "name":"Ring size"
    },
    {
    "values":[
    "Chocolate",
    "Blue",
    "Two-Tone"
    ],
    "name":"Metal Color"
    }
    ]

Notice that the metal color options block being at the bottom of the options array makes the api call work. I am almost positive this has something todo with this changelog here I mean, if anyone at the tech team can confirm this is a bug that would be dope.

I am more than happy to supply full postmans and our account info along with the app that we are using to help better your debugging process just please reach out and assist with this issue.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 80 253

Would you mind giving me an example create request, followed by an example update request? That will allow me to more accurately replicate the issue on my end.

0 Likes
Highlighted
Tourist
3 0 1

Sure I can give you two packets of things that will replicate this issue. Also the first one is a post the second a put

 

Create Product:

{"product":{"body_html":"<strong>Heat up your style with this burnt orange carnelian ring, featuring lacy floral shapes on either side of the sterling silver band.<\u002fstrong>","handle":"INV-CC7","id":null,"images":[{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":[null],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":[null],"width":200}],"options":[{"name":"Ring size","values":["10.0","8.0","6.0","9.0","7.0"]}],"product_type":"Ring","published_at":"2019-07-17T07:21:47Z","tags":null,"title":"Sunkissed Ring","variants":[{"fulfillment_service":"manual","id":null,"inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":null,"key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":null,"key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"10.0","option2":null,"option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj6","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":null,"inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":null,"key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":null,"key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"8.0","option2":null,"option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj8","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":null,"inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":null,"key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":null,"key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"6.0","option2":null,"option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj7","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":null,"inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":null,"key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":null,"key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"9.0","option2":null,"option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj9","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":null,"inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":null,"key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":null,"key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"7.0","option2":null,"option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17bprb","title":"Sunkissed Ring"}],"vendor":"honora"}}

 

 

Update product

{"product":{"body_html":"Heat up your style with this burnt orange carnelian ring, featuring lacy floral shapes on either side of the sterling silver band.<\u002fstrong>","handle":"INV-CC7","id":"1899104600110","images":[{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":["17046475800622"],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":["17046475800622"],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":["17046475800622"],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":["17046475800622"],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":["17046475833390"],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":["17046475833390"],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":["17046475833390"],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":["17046475833390"],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":["17046475866158"],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":["17046475866158"],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":["17046475866158"],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":["17046475866158"],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":["17046475898926"],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":["17046475898926"],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":["17046475898926"],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":["17046475898926"],"width":200},{"height":200,"position":1,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/P/2/INV/800/hello.jpg","variant_ids":["17046475964462"],"width":200},{"height":200,"position":2,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/F/2/INV/800/hello.jpg","variant_ids":["17046475964462"],"width":200},{"height":200,"position":3,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/S/2/INV/800/hello.jpg","variant_ids":["17046475964462"],"width":200},{"height":200,"position":4,"src":"https://qa-images1.gemvaraaws.com/image-generator/SBN45462SCOP/M1/1/INV/800/hello.jpg","variant_ids":["17046475964462"],"width":200}],"options":[{"name":"Metal Type","values":["Silver"]},{"name":"Ring size","values":["10.0","8.0","6.0","9.0","7.0"]}],"product_type":"Ring","published_at":"2019-07-17T07:24:17Z","tags":null,"title":"Sunkissed Ring","variants":[{"fulfillment_service":"manual","id":"17046475800622","inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":"6796835422254","key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":"6796835455022","key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"Silver","option2":"10.0","option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj6","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":"17046475833390","inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":"6796835487790","key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":"6796835520558","key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"Silver","option2":"8.0","option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj8","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":"17046475866158","inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":"6796835553326","key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":"6796835586094","key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"Silver","option2":"6.0","option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj7","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":"17046475898926","inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":"6796835618862","key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":"6796835651630","key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"Silver","option2":"9.0","option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17brj9","title":"Sunkissed Ring"},{"fulfillment_service":"manual","id":"17046475964462","inventory_management":"shopify","inventory_policy":"deny","inventory_quantity":null,"metafields":[{"description":"Unique ID for VG designs","id":"6796835684398","key":"vgDesignName","namespace":"global","value":"INV-CC7","value_type":"string"},{"description":"Site channel ID for specific VG sku","id":"6796835717166","key":"vgVendorName","namespace":"global","value":"honora","value_type":"string"}],"option1":"Silver","option2":"7.0","option3":null,"price":"89.0","product_id":null,"published_at":null,"sku":"17bprb","title":"Sunkissed Ring"}],"vendor":"honora"}}
0 Likes
Highlighted
Shopify Staff
Shopify Staff
1555 80 253

So it looks like you're updating with a lot of information you may not need. In my experience, this has led to confusion on what exactly is wrong. Your requests will also be much more performant when you're not posting redundant data. I was able to make it work like so:

 

{
	"product": {
		"variants": [
			{
				"id": 19534747500566,
				"option2": "Silver",
				"option1": "10.0",
				"price": "89.0"
			},
			{
				"id": 19534747533334,
				"option2": "Silver",
				"option1": "8.0",
				"price": "89.0"
			},
			{
				"id": 19534747566102,
				"option2": "Silver",
				"option1": "6.0",
				"price": "89.0"
			},
			{
				"id": 19534747598870,
				"option2": "Silver",
				"option1": "9.0",
				"price": "89.0"
			},
			{
				"id": 19534747631638,
				"option2": "Silver",
				"option1": "7.0",
				"price": "89.0"
			}
		]
	}
}

The first thing that I noticed is that in your following update request, you're overriding the existing option1 with your new option. Moving Silver to option2 gave me success.

 

Cheers.

0 Likes