Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
On the admin page, we can create a product within a selected category. Products in a category can have predefined metafields to choose from. Is there a standard way to access these category metafields through the API?
Hey @wangli29751 this query is relates to Shopify's Product Taxonomy and Category Metafields, a newer feature that helps with product attributes like (material, color, etc.) based on the assigned product category.
When creating products via the GraphQL Admin API, you can access and assign category-based metafields, but there are some important details to keep in mind.
1: Why are category Metafields?
Now the Question is that how to access Category metafield via GraphQL?
There is a standardized way to fetch and use these via GraphQL Admin API. Just follow these steps.
query {
productCategorySuggestions(query: "t-shirt") {
productTaxonomyNode {
id
name
fullName
}
}
}
query {
productTaxonomyNode(id: "gid://shopify/ProductTaxonomyNode/12345") {
id
name
metafieldDefinitions(first: 50) {
edges {
node {
id
name
key
namespace
type {
name
}
}
}
}
}
}
mutation {
productCreate(input: {
title: "Nike Air Max",
productCategory: {
productTaxonomyNodeId: "gid://shopify/ProductTaxonomyNode/12345"
}
}) {
product {
id
title
}
userErrors {
field
message
}
}
}
mutation {
metafieldsSet(metafields: [
{
ownerId: "gid://shopify/Product/PRODUCT_ID",
namespace: "standard",
key: "material",
type: "single_line_text_field",
value: "Cotton"
}
]) {
metafields {
id
key
value
}
userErrors {
field
message
}
}
}
By following these steps you will be able to use category Metafields in Product creation via the GraphQL API.
if this was really helpful prove it via like and Mark as Solution.
Thank you for your reply, but it appears that none of the queries or mutations you provided were valid.
Hey there! I'm trying to create a Product using the Shopify Admin GraphiQL API, set its Category, and add Metafields for that Category. I saw your reply in a post, which was super helpful, but when I tried your approach with the new 2025-04 version, I ran into issues. It seems like `productCategorySuggestions` is deprecated in this version, and my query returned some errors. Can you help me figure out how to achieve this with the 2025-04 version of the Shopify Admin GraphiQL API?
{
"query": "query { productCategorySuggestions(query: \"t-shirt\") { productTaxonomyNode { id name fullName } } }",
"variables": {
"sku": "916042",
"first": 5
}
}
{
"errors": [
{
"message": "Field 'productCategorySuggestions' doesn't exist on type 'QueryRoot'",
"locations": [
{
"line": 1,
"column": 9
}
],
"path": [
"query",
"productCategorySuggestions"
],
"extensions": {
"code": "undefinedField",
"typeName": "QueryRoot",
"fieldName": "productCategorySuggestions"
}
}
]
}
Hi, Wangli
Yes, there is a standard way to access category metafields through the API in various eCommerce platforms like Shopify, WooCommerce, and others. Here, I will explain how you might approach this depending on the platform you are working with. Since many platforms, like Shopify, allow for category-specific metafields, let's start with a more general guide and dive into specifics for Shopify.
There are some categories metafields using these APIs
Shopify and WooCommerce (Wordpress)
Only AI bots here 😪
Learn 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, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025