What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

GraphQL support for Product Category Attributes/Metafields

GraphQL support for Product Category Attributes/Metafields

JustinKillian
Shopify Partner
28 0 18

Hello there,

My team is exploring the idea of supporting Product Categories and Product Category Attributes/Metafields in our app.

 

I see that the latest GraphQL Admin release (2024-07) already supports the category field as part of the `productSet`, `productCreate`, and `productUpdate` mutations.

 

Unless it's already supported (if so, please let me know where I can find the documentation), is Shopify planning to support Product Category Attributes/Metafields, as well as any related functionality such as attribute-based options, in the upcoming GraphQL releases?

 

Thanks!

Replies 5 (5)

Kyle_liu
Shopify Partner
304 41 54

Hi @JustinKillian 

 

Taking productSet as an example:

Kyle_liu_0-1721275832908.png

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee

stormyshippy
Shopify Partner
2 0 0

This may not answer your complete question, but from what I can gather the GraphQL Admin treats "Product Category Metafields" similar to any other product level metafield. In other words, if you request a product's metafields, you will also be able to retrieve the "Category Metafields" set on that product.

 

For instance, I added a "Category Metafield" for "color" to a product and selected two different color values. Here is the product metafield associated with that same action on the product:

 

{
"__parentId": "gid://shopify/Product/8769546223889",
"id": "gid://shopify/Metafield/45476347379985",
"key": "color-pattern",
"namespace": "shopify",
"type": "list.metaobject_reference",
"updatedAt": "2024-08-14T21:03:34Z",
"value": "[\"gid://shopify/Metaobject/74614309137\",\"gid://shopify/Metaobject/74614276369\"]"
}

JustinKillian
Shopify Partner
28 0 18

Hello @stormyshippy ,

 

Thank you for your reply! I am curious - if you don't mind me asking - were the color metafield and the color values set using the Shopify Admin UI or via the Graphql API?

If they were set via the API, could you please share where the ids in format `gid://shopify/Metaobject/:id` are coming from? I am curious to know if those IDs are global and publicly exposed by Shopify similarly to how the category tree is exposed.

Thanks!

stormyshippy
Shopify Partner
2 0 0

They were set via the Shopify Admin UI.

 

The values are globally unique and different for each store, so they aren't similar to how the ones in the category tree are exposed.

 

I wasn't able to find any clear approach via API to accomplish the same task as what is made quite simple in the UI of selecting a product category hierarchy node and then adding a category metafield values.

 

Adding the product category to a product via API is straightforward and the values of the category ID are global and are the exact ones that are part of the category taxonomy tree.

 

   mutation {
     productCreate(input: {
       title: "Sample Product",
       vendor: "SampleVendor",
       productType: "DEFAULT_TYPE",
       category: "gid://shopify/TaxonomyCategory/ap-2-16"
     }) {
       product {
         id
         title
         category {
						id
         }
       }
       userErrors {
         field
         message
       }
     }
   }

 

JustinKillian
Shopify Partner
28 0 18

Thanks a lot, stormyshippy!

I agree, there is no way to implement category metafields via API in the same way it's supported in the Admin UI.

I would love to see this supported. I will keep this thread opened. Hopefully someone from Shopify help us taking a look and let us know if there is a way to do category metafields via API and we are just not aware of it.

Thanks