FROM CACHE - en_header

Options is invalid - name of option is not unique

rodrigosqquid
Tourist
4 0 3

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.

Replies 8 (8)
_JB
Shopify Staff
Shopify Staff
836 99 211

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

Ivan_Milic
Shopify Partner
4 0 3

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:

Ivan_Milic_0-1619505288251.png

But this update product QL produces same problem (note before this update call product had only 'Size' option): 

mutation{  productUpdate (input:{
 id: "gid://shopify/Product/6630751109306" 
 title: "Frances Denim Skirt" 
 options: ["Color","Size"] 
 images: [  ] 
 tags: ["-SPRING 2021-","Bottoms","full price","price_Over $80","related_tag_SS21-7","size_L","size_M","size_S","Size_XL","size_XS","SS21"] 
 publishedAt: null 
 status: DRAFT 
 variants: [
{ id: "gid:\/\/shopify\/ProductVariant\/39588518297786" options: ["Blue","XS"] }
{ id: "gid:\/\/shopify\/ProductVariant\/39588518330554" options: ["Blue","S"] }
{ id: "gid:\/\/shopify\/ProductVariant\/39588518363322" options: ["Blue","M"] }
{ id: "gid:\/\/shopify\/ProductVariant\/39588518428858" options: ["Blue","L"] }
{ id: "gid:\/\/shopify\/ProductVariant\/39588518461626" options: ["Blue","XL"] }
}){
userErrors{
  field
  message
}
product{
  id
  updated_at: updatedAt
  published_at: publishedAt
  created_at: createdAt
  product_type: productType
  title: title
  handle: handle
  vendor: vendor
  status
  tags: tags
  template_suffix: templateSuffix
  gift_card_template_suffix: giftCardTemplateSuffix
  body_html: descriptionHtml
  tracksInventory
  totalVariants
  options{
  id
  name
  position
  values
  }images(first:1){
  edges{
node{
  id
  originalSrc
  transformedSrc
  altText
}
  }
}
}
}}

 

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

Ivan_Milic
Shopify Partner
4 0 3

...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

sebastjans
Tourist
5 1 2

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

APIANT
Shopify Partner
26 1 37

 

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

 

APIANT
Shopify Partner
26 1 37

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.

 

APIANT
Shopify Partner
26 1 37

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.

https://share.apiant.com/qGu5nRXY

Conner
Explorer
50 1 9

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.