Unable to insert variant when Option is linked to metafield via API

Unable to insert variant when Option is linked to metafield via API

milosbaran
Shopify Partner
4 0 0

Hi everyone,

 

Using Rest API I'm trying to insert new option variants into existing product.

When options are not linked to metafields it's working fine. But when for example "color" is linked to shopify native 

shopify.color-pattern

I get error 422: Cannot set name for an option value linked to a metafield

 

This is always the case even if the colour I want to use is predefined in the metafield.

 

 

Thanks

Milos

Replies 6 (6)

Liam
Community Manager
3108 340 871

You could try using the productVariantCreate mutation instead to see if this works with GraphQL. You could try with the GraphiQL tool and the mutation would look something like:  

 

mutation {
  productVariantCreate(input: {
    productId: "gid://shopify/Product/108828309",
    price: 114.99,
    inventoryPolicy: DENY,
    inventoryQuantities: [
      {
        availableQuantity: 25,
        locationId: "gid://shopify/Location/346779380"
      }
    ],
    inventoryItem: {
      cost: 50,
      tracked: true
    },
    requiresShipping: true,
    options: ["Holographic"]
  }) {
    productVariant {
      id
      title
      price
      inventoryQuantity
    }
    userErrors {
      field
      message
    }
  }
}

 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

milosbaran
Shopify Partner
4 0 0

Hi Liam,

 

thank you for the suggestion.

When I tried to run it and to add a new variant to product with linked option I got an error

Internal error. Looks like something went wrong on our end.
Request ID: e06ddcce-4f9b-45fa-9483-2e1709e84759-1722438715 (include this in support requests).

 

When I change product ID and tried to insert it to product without linked option it worked without an error.

 

Thanks

Milos

Liam
Community Manager
3108 340 871

Will look into this more on our side - I'm seeing an error message: "Cannot Set Name For Linked Option Value"

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

milosbaran
Shopify Partner
4 0 0

Interesting. Looks like a similar error to the one from RestAPI call. 

Thanks for looking into it

Liam
Community Manager
3108 340 871

Hi again Milos,

 

I'm connecting with our team internally here to confirm, but it sounds like adding metafield-linked options to products is not currently supported. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

milosbaran
Shopify Partner
4 0 0

Thank you for looking into it Liam!

Maybe some day it will be possible 😉

 

Milos