A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello everyone,
I'm trying to update a product and its variants using the rest api. I'm using the latest version of the API and my request is the following:
{
variants: [ { sku: '1323522109', inventory_management: 'shopify', option1: 'O/S', option2: 'DARKPLUM', id: 34081633960071 }, { sku: '1323522110', inventory_management: 'shopify', option1: 'O/S', option2: 'ORACRUSH', id: 34081633992839 } ], published: false, options: [ { name: 'Size' }, { name: 'Color' } ], id: '5007468494983' }
The API responds with a 422 status response containing the following message:
{"options":["is invalid"],"name":["of Option is not unique"]}
The message seems to point at the "options" attribute of the product. As additional info, the product and variants already exist in shopify, and the product's options array contains only Color.
Any ideas? Your help is much appreciated.
Hey @rodrigosqquid,
You're seeing this error because you're providing the same option name in option1 for both variants. Since you're not sending a unique value for size, you can omit that and just send the color options.
JB | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi,
just stumbled upon same problem. This doesn't seam logical because option combinations are unique for all 5 variants, also you can achieve this option value setup from product edit page without problem. So it looks to me that this is bug in API. If you first have one option ["Size"] then you try to add options for product and variants but move "Size" to option2 place like ["Color","Size"] you get this error.
Image showing that same can be done in default product edit page:
But this update product QL produces same problem (note before this update call product had only 'Size' option):
P.S. I'm not sure but it might be that this worked ok before and that problem appeared with recent API versions. FYI: This happened on API version 2021-01
...to add to my previous message:
I added temporal fix. If I detect this message I then make call to first rename existing options to temporally random names and then I repeat original request. It then completes with success and without a problem.
But I would like to be notified when this bug gets resolved so I could remove this bug override code from our app.
Thanks,
Ivan
Encountered exactly the same issue on my project - will try to resolve it with a workaround, but it would be really great if it could be fixed on the API level
I have the same issue, but it works in our development environment and not in production.
This is the use case where it works:
https://share.apiant.com/4gunGnRv
This product ID 4572485484644
Option 1 is "Size" with values "2" "4"
published_scope is global
status active
I apply the change here:
{
"product":{
"id": 6584696864868,
"options": [
{"name": "Color", "values": ["White"]},
{"name": "Size", "values": ["2"]}
],
"variants": [
{
"option1": "White",
"option2": "2",
"sku": "4254884628"
}
]
}
}
I was able to replace Option 1 with Color White and Option 2 with Size 2:
https://share.apiant.com/2Nuqoq8k
But in production (different store)
Product ID 4572485484644
Has just one option as well "Size" with 3 values "small" "M" "Large" ("M" is on purpose because I originally thought I couldn't add a value that already existed but the test mentioned above did work)
https://share.apiant.com/rRujAjAm
I apply the change here:
{
"product":{
"id": 4572485484644,
"options": [
{"name": "Color", "values": ["Grey"]},
{"name": "Size", "values": ["Medium"]}
],
"variants": [
{
"option1": "Grey",
"option2": "Medium",
"sku": "19DE25363"
}
]
}
}
I get this error when trying to overwrite the options and option values:
https://share.apiant.com/6qur1rAK
I was able to replicate the problem on our dev platform with the exact same product:
https://share.apiant.com/YEuZbOvx
But still can't figure out why it worked with the other product and not this one.
Here's how I solved it. Not sure it's the most efficient way, but it works.
First a recap:
I have a product with only one option "Size" that needs 2 options "Color" first then "Size"
Since the Product only has one option called "Size", I first rename that option to "Color" without providing values because I know variants already have a value for that option:
{
"product":{
"id": 6584723177572,
"options": [
{"name": "Color"}
]
}
}
Then I provide both options with values and a value for Option 2 for the variants:
{
"product":{
"id": 6584723177572,
"options": [
{"name": "Color", "values": ["Grey"]},
{"name": "Size", "values": ["small"]}
],
"variants": [
{
"option2": "small",
"sku": "19DE25362"
}
]
}
}
Finally I do an update on the variants with the proper option values:
{
"variant":{
"id": 39376928964708,
"inventory_management": "shopify",
"inventory_policy": "deny",
"option1": "Grey",
"option2": "small",
"price": "60.0000",
"taxable": true
}
}
I had to remember that after providing a second option, the variant id would change since it is technically a new variant with now 2 options. So I just had to search the variant by SKU which is why I updated the SKU when I provided the second option.
Bump. Simply excluding an option because it's not unique (despite the option combination being unique for the variant) isn't a great solution. That value can still be important to display. I'll implement the workaround suggestions in this thread for now, but fingers crossed for a fix.