Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

producCreate with linkedMetafield in 2024-07

producCreate with linkedMetafield in 2024-07

ronald_g
Explorer
80 2 16

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.

2024-07-20_21-55-21.png

Replies 11 (11)

AsafGitai
Shopify Staff
109 16 45

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

ronald_g
Explorer
80 2 16

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"]
      }
    }
  ]
}

 

 

AsafGitai
Shopify Staff
109 16 45

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




ronald_g
Explorer
80 2 16

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.

ronald_g
Explorer
80 2 16

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
      }
    }
  ]
}

 

AsafGitai
Shopify Staff
109 16 45

Looking into this with the team

AsafGitai
Shopify Staff
109 16 45

@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
        }
      }
    }
  }
}
ronald_g
Explorer
80 2 16

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"?

AsafGitai
Shopify Staff
109 16 45

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

ronald_g
Explorer
80 2 16

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.

 

 

aideveloper2
Tourist
4 0 0

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

AI developer of >10 years (Ph.D. in Physics). Main area of work: Smart categorization AI, specializing in returning categories + attributes for products in Shopify stores. You can follow me and my writings on my medium.com blog: product categorization ai blog