All things Shopify and commerce
Hi there 👋,
I’m trying to bulk create product variants using Shopify's GraphQL API. However, I’m running into a series of conflicting and confusing error messages when trying to configure optionValues, particularly when working with a linkedMetafieldValue. (shopify.color-pattern field for eg).
tldr;
curl -X POST https://<store>.myshopify.com/admin/api/2025-01/graphql.json \ -H "Content-Type: application/json" \ -H "X-Shopify-Access-Token: <redacted>" \ -d '{ "query": " mutation ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { product { id } userErrors { field message code } } }", "variables": { "productId": "gid://shopify/Product/8737843085536", "variants": [ { "barcode": "", "inventoryItem": { "cost": 0, "countryHarmonizedSystemCodes": null, "measurement": { "weight": { "unit": "OUNCES", "value": 2 } }, "requiresShipping": true, "tracked": true }, "inventoryPolicy": "DENY", "optionValues": [ { "name": "Selling Plans Ski Wax", "optionName": "Title" }, { "linkedMetafieldValue": "gid://shopify/Metaobject/103203111136" } ], "price": "24.95", "requiresComponents": false, "taxCode": "", "taxable": true } ] } }'
Response
{ "data": { "productVariantsBulkCreate": { "product": null, "userErrors": [ { "field": [ "variants", "0", "optionValues", "1" ], "message": "optionId or optionName must be specified", "code": "INVALID_INPUT" } ] } } }
Alright, fine! I'll add the optionID or optionName as suggested in the error message. I added the optionName
curl -X POST https://<store>.myshopify.com/admin/api/2025-01/graphql.json \ -H "Content-Type: application/json" \ -H "X-Shopify-Access-Token: <redacted>" \ -d '{ "query": " mutation ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { product { id } userErrors { field message code } } }", "variables": { "productId": "gid://shopify/Product/8737843085536", "variants": [ { "barcode": "", "inventoryItem": { "cost": 0, "countryHarmonizedSystemCodes": null, "measurement": { "weight": { "unit": "OUNCES", "value": 2 } }, "requiresShipping": true, "tracked": true }, "inventoryPolicy": "DENY", "optionValues": [ { "name": "Selling Plans Ski Wax", "optionName": "Title" }, { "linkedMetafieldValue": "gid://shopify/Metaobject/103203111136", "optionName": "Color" } ], "price": "24.95", "requiresComponents": false, "taxCode": "", "taxable": true } ] } }'
Response
{ "data": { "productVariantsBulkCreate": { "product": null, "userErrors": [ { "field": [ "variants", "0", "optionValues", "1" ], "message": "id or name must be specified", "code": "INVALID_INPUT" } ] } } }
OK, I'll add value id or name.
curl -X POST https://<store>.myshopify.com/admin/api/2025-01/graphql.json \ -H "Content-Type: application/json" \ -H "X-Shopify-Access-Token: <redacted>" \ -d '{ "query": " mutation ProductVariantsCreate($productId: ID!, $variants: [ProductVariantsBulkInput!]!) { productVariantsBulkCreate(productId: $productId, variants: $variants) { product { id } userErrors { field message code } } }", "variables": { "productId": "gid://shopify/Product/8737843085536", "variants": [ { "barcode": "", "inventoryItem": { "cost": 0, "countryHarmonizedSystemCodes": null, "measurement": { "weight": { "unit": "OUNCES", "value": 2 } }, "requiresShipping": true, "tracked": true }, "inventoryPolicy": "DENY", "optionValues": [ { "name": "Selling Plans Ski Wax", "optionName": "Title" }, { "linkedMetafieldValue": "gid://shopify/Metaobject/103203111136", "optionName": "Color", "name": "Red" } ], "price": "24.95", "requiresComponents": false, "taxCode": "", "taxable": true } ] } }'
Response
{ "data": { "productVariantsBulkCreate": { "product": null, "userErrors": [ { "field": [ "variants", "0", "optionValues", "1" ], "message": "Cannot set name for an option value linked to a metafield", "code": "CANNOT_SET_NAME_FOR_LINKED_OPTION_VALUE" } ] } } }
To summarize:
The error messages seem to contradict themselves. Am I missing anything obvious here? What would be the proper request payload for adding options with linkedMetafieldValue?
Thanks in advance!
I've run into the exact same issue, with the exact same set of error messages 😞
Did you find a solution to this problem by any chance?
To extends my question:
For a `productVariantsBulkUpdate` mutation, the following block should set the `optionValues`:
"optionValues": [
{
"optionName": "Color",
"name": "Red",
"linkedMetafieldValue": "gid://shopify/Metaobject/88683086037"
}
]
// error message: Cannot set name for an option value linked to a metafield
Ok, let's remove the `name`:
"optionValues": [
{
"optionName": "Color",
"linkedMetafieldValue": "gid://shopify/Metaobject/88683086037"
}
]
// error message: id or name must be specified
Ok... let's try adding an `id` instead of a `name` then?
"optionValues": [
{
"optionName": "Color",
"id": "gid://shopify/ProductOptionValue/3540024983765",
"linkedMetafieldValue": "gid://shopify/Metaobject/88683086037"
}
]
// error message: Cannot set id for an option value linked to a metafield
Maybe I need to only provide a `linkedMetafieldValue`?
"optionValues": [
{
"linkedMetafieldValue": "gid://shopify/Metaobject/88683086037"
}
]
// error message: optionId or optionName must be specified
Which basically seems to boil down to: setting a `linkedMetafieldValue` through the GraphQL API (version: 2025-04) is not supported?!
No estoy seguro, pero mi respuesta en este otro post tal vez pueda ayudar un poco.
https://community.shopify.com/c/shopify-flow-app/link-option-to-metafield/m-p/3053555/highlight/true...
Podría probar con algo asi:
"optionValues": [
{
"id": "gid://shopify/ProductOptionValue/3540024983765",
"linkedMetafieldValue": "gid://shopify/Metaobject/88683086037"
}
]
Evitando usar name ya que será tomado del metaobject referenciado.
Your solution is for updating `productOptions` with the `productOptionUpdate` mutation. This topic is about updating the `optionValues` for a product variant with the `productVariantsBulkUpdate` mutation.
June brought summer energy to our community. Members jumped in with solutions, clicked ...
By JasonH Jun 5, 2025Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025