New Shopify Certification now available: Liquid Storefronts for Theme Developers

How do you get a Product's Category using the GraphQL or Rest API?

Solved
doabledanny
Shopify Partner
12 0 6

I can get the Product Type using the GraphQL API from `Product.productType`, but I can't find any documentation on how to get the Product Category. Could someone guide me in the right direction? Thanks! 

 

doabledanny_0-1666290152421.png

 

Accepted Solution (1)
StevieW
Shopify Partner
12 1 6

This is an accepted solution.

This should help

https://shopify.dev/api/admin-graphql/2022-10/objects/ProductCategory

 

Go in via 

{
  product(id: "") {
    productCategory {
      productTaxonomyNode {
        ...
      }
    }
  }
}

 

Also, this is only available on the 2022-10 (and later) api.

View solution in original post

Replies 5 (5)
StevieW
Shopify Partner
12 1 6

This is an accepted solution.

This should help

https://shopify.dev/api/admin-graphql/2022-10/objects/ProductCategory

 

Go in via 

{
  product(id: "") {
    productCategory {
      productTaxonomyNode {
        ...
      }
    }
  }
}

 

Also, this is only available on the 2022-10 (and later) api.

doabledanny
Shopify Partner
12 0 6

Thank you! If anyone is getting null returned from this, be sure to click the tick icon on Product Category to actually accept it.

ToloLift
Shopify Partner
1 0 4

Hi,

 

I would need to retrieve the product category with the Products endpoint using the REST API.

Is this planned to be added anytime soon?

 

Thank you.

moin786ahamad
Shopify Partner
3 0 4

This is available for GraphQL. Can you please help me with the REST API mechanism to get the product category

Thanks & Regards
Moin Ahamad
Salesforce Developer
ndrtek
Shopify Partner
9 0 7

But it's not available via the Storefront GraphQL API?!

 

I need to pass the category into useServerAnalytics in my Hydrogen app.

 

G