We have encountered two issues with changing product options after they have been created in certain circumstances. They could be related, however different errors are produced.
The first issue is removing the first option from an existing product that has two options. The remaining option is moved into the place of option one.
POST new product:
{
"product": {
"title": "Burton Custom Freestyle 151",
"body_html": "<strong>Good snowboard!</strong>",
"vendor": "Burton",
"product_type": "Snowboard",
"variants": [
{
"option1": "Small",
"option2": "Red",
"price": "10.00",
"sku": "123"
},
{
"option1": "Large",
"option2": "Blue",
"price": "20.00",
"sku": "456"
}
],
"options": [
{
"name": "Size",
"values": [
"Small",
"Large"
]
},
{
"name": "Colour",
"values": [
"Red",
"Blue"
]
}
]
}
}
PUT update to product, removing the size option:
{
"product": {
"title": "Burton Custom Freestyle 151",
"body_html": "<strong>Good snowboard!</strong>",
"vendor": "Burton",
"product_type": "Snowboard",
"variants": [
{
"option1": "Red",
"price": "10.00",
"sku": "123"
},
{
"option1": "Blue",
"price": "20.00",
"sku": "456"
}
],
"options": [
{
"name": "Colour",
"values": [
"Red",
"Blue"
]
}
]
}
}
Result:
{"errors": {"base": ["could not be saved successfully"]}}
The second issue is basically the opposite, when a product already has one option and a new option is added before the existing option. So option 1 moves to option 2, and the new option is inserted as option 1. This is necessary as our application always prioritises size over colour, but some products may initially have only a colour, and the size is then added later.
POST new product:
{"product":{"title":"Error adding option","variants":[{"price":20,"sku":"error1","option1":"Blue"},{"price":20,"sku":"error2","option1":"Red"}],"options":[{"name":"Colour","values":["Blue","Red"]}]}}
PUT product update, adding size option (replace XXXXXXXX with variant IDs):
{"product":{"vendor":null,"variants":[{"price":20,"sku":"error1","option1":"Small","option2":"Blue","id":XXXXXXXX},{"price":20,"sku":"error2","option1":"Large","option2":"Red","id":XXXXXXXX}],"options":[{"name":"Size","values":["Small","Large"]},{"name":"Colour","values":["Blue","Red"]}]}}
Result:
{"errors": {
"options": ["is invalid"],
"name": ["of Option is not unique"]
}}
However, the PUT request does work when the vendor field is removed (which we sometimes need to update simultaneously):
{"product":{"variants":[{"price":20,"sku":"error1","option1":"Small","option2":"Blue","id":XXXXXXXX},{"price":20,"sku":"error2","option1":"Large","option2":"Red","id":XXXXXXXX}],"options":[{"name":"Size","values":["Small","Large"]},{"name":"Colour","values":["Blue","Red"]}]}}
The PUT request also works when the options are in the original order, so the existing option remains as option1 and the new option is option2:
{"product":{"vendor":null,"variants":[{"price":20,"sku":"error1","option1":"Blue","option2":"Small","id":XXXXXXXX},{"price":20,"sku":"error2","option1":"Red","option2":"Large","id":XXXXXXXX}],"options":[{"name":"Colour","values":["Blue","Red"]},{"name":"Size","values":["Small","Large"]}]}}
If anyone is able to figure out what's going on here, that would be awesome.
I tried something and it worked. Uptil now we know that something is wrong with Shopify API when we try to PUT (update) an existing product and moving the existing option to second position.
The existing product had one option called "Color" and a PUT request to add an option "Size" on the first position and more "Color" to second position resulted in the following response (422):
{"errors":{"options":["is invalid"],"name":["of Option is not unique"]}}
To work around this issue, I broke my request into two requests:
That's how I succeeded in achieving my goal. I hope this helps someone looking for an answer. Thanks.
I'm having a very similar issue, as exposed here. Can anyone tell me if the root cause has been found?
User | Count |
---|---|
13 | |
12 | |
7 | |
4 | |
4 |