Subject: Fetching Product Categories and Subcategories from Shopify Seller Stores

I am building a connector to fetch products from Shopify sellers’ stores and add them to our portal for the respective seller. However, Shopify does not provide direct product category and subcategory data. How can I accurately determine and classify products into their correct categories and subcategories?

for eg.
this is one of the response
{
“id”: 7677173530742,
“title”: “Bottle”,
“body_html”: “

Bottle

”,
“vendor”: “Anand Super Mart”,
“product_type”: “Bottle”,
“created_at”: “2025-02-24T16:21:17+05:30”,
“handle”: “bottle”,
“updated_at”: “2025-02-25T04:23:13+05:30”,
“published_at”: “2025-02-24T16:21:17+05:30”,
“template_suffix”: “”,
“published_scope”: “global”,
“tags”: “Bottle”,
“status”: “active”,
“admin_graphql_api_id”: “gid://shopify/Product/7677173530742”,
“variants”: [
{
“id”: 42026177822838,
“product_id”: 7677173530742,
“title”: “1 L / Black”,
“price”: “199.00”,
“position”: 1,
“inventory_policy”: “deny”,
“compare_at_price”: null,
“option1”: “1 L”,
“option2”: “Black”,
“option3”: null,
“created_at”: “2025-02-24T16:21:19+05:30”,
“updated_at”: “2025-02-24T16:21:19+05:30”,
“taxable”: true,
“barcode”: “”,
“fulfillment_service”: “manual”,
“grams”: 10,
“inventory_management”: “shopify”,
“requires_shipping”: true,
“sku”: “1233”,
“weight”: 10.0,
“weight_unit”: “g”,
“inventory_item_id”: 44128635256950,
“inventory_quantity”: 0,
“old_inventory_quantity”: 0,
“admin_graphql_api_id”: “gid://shopify/ProductVariant/42026177822838”,
“image_id”: null
},
{
“id”: 42026177855606,
“product_id”: 7677173530742,
“title”: “2 L / Black”,
“price”: “199.00”,
“position”: 2,
“inventory_policy”: “deny”,
“compare_at_price”: null,
“option1”: “2 L”,
“option2”: “Black”,
“option3”: null,
“created_at”: “2025-02-24T16:21:19+05:30”,
“updated_at”: “2025-02-24T16:21:19+05:30”,
“taxable”: true,
“barcode”: “”,
“fulfillment_service”: “manual”,
“grams”: 10,
“inventory_management”: “shopify”,
“requires_shipping”: true,
“sku”: “1234”,
“weight”: 10.0,
“weight_unit”: “g”,
“inventory_item_id”: 44128635289718,
“inventory_quantity”: 0,
“old_inventory_quantity”: 0,
“admin_graphql_api_id”: “gid://shopify/ProductVariant/42026177855606”,
“image_id”: null
}
],
“options”: [
{
“id”: 10138382205046,
“product_id”: 7677173530742,
“name”: “size”,
“position”: 1,
“values”: [
“1 L”,
“2 L”
]
},
{
“id”: 10138382237814,
“product_id”: 7677173530742,
“name”: “Color”,
“position”: 2,
“values”: [
“Black”
]
}
],
“images”: [
{
“id”: 33434805469302,
“alt”: null,
“position”: 1,
“product_id”: 7677173530742,
“created_at”: “2025-02-24T16:17:32+05:30”,
“updated_at”: “2025-02-24T16:17:34+05:30”,
“admin_graphql_api_id”: “gid://shopify/ProductImage/33434805469302”,
“width”: 835,
“height”: 823,
“src”: “https://cdn.shopify.com/s/files/1/0612/9365/8230/files/MicrosoftTeams-image_3.png?v=1740394054”,
“variant_ids”:
}
],
“image”: {
“id”: 33434805469302,
“alt”: null,
“position”: 1,
“product_id”: 7677173530742,
“created_at”: “2025-02-24T16:17:32+05:30”,
“updated_at”: “2025-02-24T16:17:34+05:30”,
“admin_graphql_api_id”: “gid://shopify/ProductImage/33434805469302”,
“width”: 835,
“height”: 823,
“src”: “https://cdn.shopify.com/s/files/1/0612/9365/8230/files/MicrosoftTeams-image_3.png?v=1740394054”,
“variant_ids”:
}
}

Hi Tejas,

You should be able to get the product category by specifying it when you’re querying the product, eg:

query GetProductCategory {
  product(id: "gid://shopify/Product/9403683242326") {
    id
    title
    category {
      id
      name
      fullName
      parentId
    }
  }
}

This should return something like this:

{
  "data": {
    "product": {
      "id": "gid://shopify/Product/9403683242326",
      "title": "The Collection Snowboard: Liquid",
      "category": {
        "id": "gid://shopify/TaxonomyCategory/sg-4-17-2-17",
        "name": "Snowboards",
        "fullName": "Sporting Goods > Outdoor Recreation > Winter Sports & Activities > Skiing & Snowboarding > Snowboards",
        "parentId": "gid://shopify/TaxonomyCategory/sg-4-17-2"
      }
    }
  },