Hi. I’m using the Graphql API to upload products and need some assistance with the process of setting the category metafields (seen in the attached image).
To upload products, I’m using the productSet mutation, which works for populating all of the data that I’m working with right now so far, so I’d like to continue using that mutation only if it’s possible. I was reading online about needing to possibly create metaobjects before populating the metafields, but these ones should already be created by Shopify, right? Anyways, I’d really appreciate a quick workflow and example mutation of how to set the color to black (preferably within the productSet mutation).
Hey @Adam_Heaney - you’re correct that these category metafields are available for merchants to easily associate with their products through the admin (more info here), but they still do technically have to “add” the category metafields if that makes sense.
We do have a standard list of these definitions that you can use to initially “create” the metaobject on a shop though: Standard metaobject definitions.
Once you have the taxonomy definitions you want to use, you’d just follow this guide here to add the metafields to the product: Metafield-linked product options
Hopefully this helps/makes sense, let me know if I can clarify anything on my end here or help out further.
We have a tool in a PIM-like tool that is using the Shopify Taxonomy category but also the TaxonomyValue. The problem is that to use this on the product, we need the MetaobjectID on the Category Metafields.
We cannot find the mapping between the TaxonomyValue and the Metaobject in the Taxonomy Github. Is this due to the fact that the GID is globally unique?
So we looked at option 2:
Loop over all the Definitions with metaobjectDefinitions.
Get the Metafields via the metaobjectDefinition > Metafields edge.
Now, here there are only the options that the merchants have selected in the past.
So when we inspect the Shopify Admin, we see the suggestedMetaobjects. This gets all the available options under, for instance, battery size. Can I assume that Shopify is creating the Metaobject when the merchant selects an option out of this list?
So how can we get the options Shopify already has and map those to the TaxonomyValue?
Screenshot showing the values are not in the GraphQL API:
The GraphQL taxonomy query is an easier way to grab those TaxonomyValue GIDs directly if needed. For example, for a given product category, you can traverse its attributes, and for any TaxonomyChoiceListAttribute (like Color, Battery Size, etc.), you can fetch all possible TaxonomyValue nodes with their stable GIDs like this:
query GetTaxonomyValues {
taxonomy {
categories(first:20, search: "Apparel") {
nodes {
id
fullName
attributes(first: 10) {
nodes {
... on TaxonomyChoiceListAttribute {
id
name
values(first: 50) {
nodes {
id
name
}
}
}
}
}
}
}
}
}
This should give you things like { id: "gid://shopify/TaxonomyValue/3", name: "Black" }. Those GIDs are stable and are exactly what you’d use as color_taxonomy_reference values when creating your metaobject entries.
suggestedMetaobjects aren’t part of our public API, but you may have come across it outside of the standard public API surface, which wouldn’t be something you could reliably depend on in your PIM tool. Right now, the taxonomy query is the best path to get that same universe of available values though.
And just to confirm as well, you’re correct that you’d only see metaobject entries that have actually been created using your second option there (i.e., values merchants have previously selected/saved). That approach will likely always be incomplete since you’d need the full list of possible **TaxonomyValue**s, not just the ones already used in that store if that makes sense.
The flow for your PIM tool that I’d suggest would be something like:
Use the taxonomy query to fetch TaxonomyValue IDs for the attributes relevant to your product category
Use those GIDs as references when creating/upserting metaobject entries via metaobjectUpsert or metaobjectCreate
Set the product’s category metafield using the resulting metaobject GID
Hope that clarifies things! Let me know if I can help out further.