producCreate with linkedMetafield in 2024-07

Topic summary

Creating products with options linked to metafields via GraphQL (2024-07) is error-prone and under-documented.

  • Supplying productOptions.values alongside linkedMetafield triggers “Cannot specify ‘values’ for an option linked to a metafield.” Using only linkedMetafield.values can still fail with “At least one value … is invalid.”

  • Staff confirmed the second pattern is correct. The “invalid” error occurs when one or more provided metaobject IDs aren’t valid allowed values for that option in that store.

  • Metaobjects are not shared across stores; each store maintains its own under Settings > Custom data. Cloning products across stores requires creating equivalent metaobjects in the target store and using that store’s IDs.

  • A staff-provided mutation worked in their test, but a user saw failures until they created the metaobjects via the Admin UI, after which creation succeeded.

  • Open issues: How to programmatically create or retrieve the category-linked metaobjects (e.g., for namespace “shopify”, key “size”/“color-pattern”) via GraphQL remains unclear. Documentation appears outdated/insufficient, and users request guidance for cross-store replication.

  • Status: Ongoing. Staff requested exact inputs/store details; no definitive API guidance yet. An additional user reports the same problem.

Summarized with AI on December 18. AI used: gpt-5.

It looks like we should be able to create products with linkedMetafields now, but the documentation on shopify.dev seems out of date and the examples don’t work.

For example, this GraphQL productCreate (2024-07) mutation raises error “Cannot specify ‘values’ for an option linked to a metafield.” It’s unclear what goes in productOptions.values.linkedMetafieldValue and what goes in productOptions.linkedMetafield.values. The documentation’s explanation doesn’t clarify anything. Anyone got linkedMetafield to work?

This input below raises “Cannot specify ‘values’ for an option linked to a metafield.”

{
  title: "Product Test",
  status: "ACTIVE",
  category: "gid://shopify/TaxonomyCategory/hg-13-9",
  productOptions: [
    {
      name: "Color",
      position: 1,
      values: 
        { name: "Green", linkedMetafieldValue: "gid://shopify/Metaobject/65800667298" }
        { name: "Clear", linkedMetafieldValue: "gid://shopify/Metaobject/65800339618" },
        { name: "Brown", linkedMetafieldValue: "gid://shopify/Metaobject/65800700066" } 
      ],
      linkedMetafield: {
        namespace: "shopify",
        key: "color-pattern",
        values: ["gid://shopify/Metaobject/65800667298", "gid://shopify/Metaobject/65800339618", "gid://shopify/Metaobject/65800700066"]
      }
    }
  ]
}

This input below raises “At least one value for the option linked to the ‘shopify.color-pattern’ metafield is invalid”

{
  title: "Product Test",
  status: "ACTIVE",
  category: "gid://shopify/TaxonomyCategory/hg-13-9",
  productOptions: [
    {
      name: "Color",
      position: 1,
      values: 
      linkedMetafield: {
        namespace: "shopify",
        key: "color-pattern",
        values: ["gid://shopify/Metaobject/65800667298", "gid://shopify/Metaobject/65800339618", "gid://shopify/Metaobject/65800700066"]
      }
    }
  ]
}

Here’s the pretty obtuse explanation on how to use linkedMetafields.

Hi @ronald_g ,

Your second example looks correct and the team just tested it on 2024-07.
That error would if one of the metaobjects is not a valid color - so it’s likely an invalid metaobject ID.
lt me know if that works

Hi @AsafGitai ,

It seems that the Metaobjects are not shared across all stores. For example, in one store, the graphQL metaobject(id: “gid://shopify/Metaobject/65800667298”) returned “Green” but another store it returned nil.

I have a few follow up questions:

  1. Are these metaobjects shared across stores or does each store have it’s own metaobjects? For example, if I’m using category = “gid://shopify/TaxonomyCategory/hg-13-9”, are the linkedMetafieldValue the same for each Color, or is it different for each store?
  2. If store A has product options with linkedMetafieldValue, how should we create the same product options in a different store?
{
  title: "Product Test",
  status: "ACTIVE",
  category: "gid://shopify/TaxonomyCategory/hg-13-9",
  productOptions: [
    {
      name: "Color",
      position: 1,
      values: 
      linkedMetafield: {
        namespace: "shopify",
        key: "color-pattern",
        values: ["gid://shopify/Metaobject/65800667298", "gid://shopify/Metaobject/65800339618", "gid://shopify/Metaobject/65800700066"]
      }
    }
  ]
}
  1. metaobjects are not shared across stores - they are defined in each store under settings->custom data.
    Please let me know where our documentation can be improved on this/what led you to think otherwise.

  2. If store A has product options with linkedMetafieldValue, how should we create the same product options in a different store?
    not sure i understand the question

Thanks @AsafGitai .

If store A has a product with a category and product options that have linkedMetafieldValue. How would we create the same product in another store? Without linkedMetafieldValue, it’s fairly straight forward. However, if the original product has linkedMetafieldValue, how would we create the product options since linkedMetafieldValue is unique per store, so we can’t simply reuse the same linkedMetafieldValue.

Hi @AsafGitai ,

Just to add, we tried using metaojbects created when creating a new product with a specific category. We ran metaobject query and ensured that these metaobjects exist in the store. However, when we tried to create product using params below, we still get "At least one value for the option linked to the ‘shopify.color-pattern’ metafield is invalid. See x-request-id: “5aef38da-857d-46de-9aca-fad890029639-1721971500”

{
  title:  "Test product",
  status: "ACTIVE",
  category: "gid://shopify/TaxonomyCategory/hg-3-64", # Throw Pillows
  productOptions: [
    {
      name: "Cover color",
      linkedMetafield: {
        namespace: "shopify",
        key: "color-pattern", # type = "shopify--color-pattern"
        values: ["gid://shopify/Metaobject/52316569767", "gid://shopify/Metaobject/52316602535", "gid://shopify/Metaobject/52316635303"]  # Bronze, Gold, Blue
      }
    }
  ]
}

Looking into this with the team

@ronald_g we were able to create a product with this input. hope it helps find the issue

mutation productCreate {
  productCreate(input: {
    title: "Linked option product test",
    category: "gid://shopify/TaxonomyCategory/aa-1-13-7",
    productOptions: [
      { 
        name: "Size",
        linkedMetafield: {
          namespace: "shopify",
          key: "size",
          values: [
            "gid://shopify/Metaobject/43003248699",
            "gid://shopify/Metaobject/38602899515"
          ]
        }
      }
    ]
  }), {
    userErrors { message }
    product {
      id
      metafields(first: 10) {
        nodes {
          namespace
          key
          value
        }
      }
      options {
        name
        optionValues {
          name
          linkedMetafieldValue
        }
      }
    }
  }
}

Thank you @AsafGitai

I copy and pasted this into our test store’s GraphiQL and got this error:

“At least one value for the option linked to the ‘shopify.size’ metafield is invalid”

I assume this is because the metaobjects don’t exist yet. So I guess the root question is how to create the metaobjects for “gid://shopify/TaxonomyCategory/aa-1-13-7” with namespace: “shopify” and key: “size”?

Sorry for the late reply here.
Could you send me the exact input and store you used and we will test this out on our side

Hi @AsafGitai ,

We did some more testing. I think something was wrong with how the specific metaobject was created. We tried a new metaobject (created via Shopify admin UI) and it worked.

However, we still don’t know how to create metaobjects related to categories via GraphQL. In Shopify admin, we can select a category, then we can add Product options that are linked to the category. The product options have metaobject already attached. However, how do we do that via GraphQL? There’s no documentation on this.

1 Like

Hello, we have the exact same problem. Did you manage to find a solution