Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
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
You could try using the product
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
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
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
Interesting. Looks like a similar error to the one from RestAPI call.
Thanks for looking into it
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
Thank you for looking into it Liam!
Maybe some day it will be possible 😉
Milos