When I update a product with multiple variants, I get an error response:
{"errors":{"base":["Options are not unique"]}}
or sometimes:
{"errors":{"variants":["is invalid"], "base":["Options are not unique"]}}
I am making a PUT request to something like /admin/products/122821632.json with data like:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"},
{"option1":"TINY",
"sku":"test-sku-1",
"product_id":"122821632",
"id":"282990692",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
I have noticed however that if I put a single variant, and then put the multiple variant data JSON, it works. This does mean deleting a variant and re-creating it, which I don't think is acceptable behaviour for a plugin, especially seeing as I don't have all the data about a variant stored, and therefore cannot be rolled out into production.
To do this I make these PUT requests:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
Which returns a 200. Followed by:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"},
{"option1":"TINY",
"sku":"test-sku-1",
"product_id":"122821632",
"id":"282990692",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
Which returns a 200. Followed by:
{"product":{"id":"122821632",
"body_html":"test",
"vendor":"Acme",
"title":"Monkey T-Shirt",
"variants":[{"option1":"LARGE",
"sku":"test-sku-2",
"product_id":"122821632",
"id":"282988194",
"price":"21.99",
"grams":"200"},
{"option1":"TINY",
"sku":"test-sku-1",
"product_id":"122821632",
"id":"282990692",
"price":"21.99",
"grams":"200"}],
"options":[{"position":1,
"name":"Size",
"product_id":"122821632"}]}}
Which gives me the error. Also the IDs of the variant I deleted and recreated has changed (which I can tell with a get request):
{"product":{"body_html":"test",
"handle":"69",
"images":[],
"template_suffix":null,
"product_type":"Shirts",
"updated_at":"2013-03-07T11:36:51-05:00",
"variants":[{"position":1,
"option1":"LARGE",
"option2":null,
"option3":null,
"updated_at":"2013-03-07T07:30:15-05:00",
"inventory_quantity":1,
"title":"LARGE",
"product_id":122821632,
"created_at":"2013-03-06T11:03:36-05:00",
"compare_at_price":"24.99",
"fulfillment_service":"manual",
"inventory_management":"",
"sku":"test-sku-2",
"taxable":true,
"requires_shipping":true,
"price":"21.99",
"inventory_policy":"deny",
"id":282988194,
"grams":200},
{"position":2,
"option1":"TINY",
"option2":null,
"option3":null,
"updated_at":"2013-03-07T11:36:51-05:00",
"inventory_quantity":1,
"title":"TINY",
"product_id":122821632,
"created_at":"2013-03-07T11:36:51-05:00",
"compare_at_price":null,
"fulfillment_service":"manual",
"inventory_management":null,
"sku":"test-sku-1",
"taxable":true,
"requires_shipping":true,
"price":"21.99",
"inventory_policy":"deny",
"id":283397624,
"grams":200}],
"title":"Monkey T-Shirt",
"created_at":"2013-02-22T05:35:02-05:00",
"options":[{"id":147204272,
"name":"Size",
"position":1,
"product_id":122821632}],
"vendor":"Acme",
"id":122821632,
"published_at":"2013-02-22T05:35:02-05:00",
"tags":"mens t-shirt example"}}
I am under the impression that the second PUT request of the same data to the same URL should result in no change.
What am I doing wrong? Is this a bug in the Shopify API?