I need to filter products by productTaxonomyNode id

I need to filter products by productTaxonomyNode id, but I don’t found a solution, I have this

if (filters?.categoryId) {
      _query += `productCategory.productTaxonomyNode.id:gid://shopify/ProductTaxonomyNode/334 `;
    }

    const query = `
      query {
        products(
          ${_query.length > 0 ? `query: "${_query}"` : ''}
          first: ${pageSize}) {
            edges {
                node {
                    id
                    title
                    createdAt
                    description
                    descriptionHtml
                    hasOnlyDefaultVariant
                    hasOutOfStockVariants
                    totalInventory
                    totalVariants
                    tracksInventory
                    featuredImage{
                      url
                    }
                    productCategory{
                      productTaxonomyNode{
                        id
                        name            
                      }
                    }
                    priceRange {
                        minVariantPrice {
                            amount
                            currencyCode
                        }
                    }
                    options{
                      id
                      name
                      position
                      values
                    }
                    variants(first:250){
                      edges{
                        node{
                          availableForSale
                          barcode
                          compareAtPrice
                          price
                          id
                          image{
                            url
                            originalSrc
                            src
                          }
                          inventoryQuantity
                          position
                          sku
                          title
                          weight
                          requiresShipping                        
                        }
                      }
                    }
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }    
  `;

this code print:

query {
        products(
          query: "productCategory.productTaxonomyNode.id:gid://shopify/ProductTaxonomyNode/334"
          first: 25) {
            edges {
                node {
                    id
                    title
                    createdAt
                    description
                    descriptionHtml
                    hasOnlyDefaultVariant
                    hasOutOfStockVariants
                    totalInventory
                    totalVariants
                    tracksInventory
                    featuredImage{
                      url
                    }
                    productCategory{
                      productTaxonomyNode{
                        id
                        name            
                      }
                    }
                    priceRange {
                        minVariantPrice {
                            amount
                            currencyCode
                        }
                    }
                    options{
                      id
                      name
                      position
                      values
                    }
                    variants(first:250){
                      edges{
                        node{
                          availableForSale
                          barcode
                          compareAtPrice
                          price
                          id
                          image{
                            url
                            originalSrc
                            src
                          }
                          inventoryQuantity
                          position
                          sku
                          title
                          weight
                          requiresShipping                        
                        }
                      }
                    }
                }
            }
            pageInfo {
                hasNextPage
                hasPreviousPage
                startCursor
                endCursor
            }
        }
    }

but I don’t have the products filtered by the productTaxonomyNode id, what I can do?

Hey @AlanDev ,

Thanks for sharing that example. Currently, the category or taxonomy node is not an available filter parameter for products queries.

You can see a list of available queries you can use here: https://shopify.dev/docs/api/admin-graphql/2024-01/queries/products#argument-query

As a workaround, you could tag the products with their taxonomy so you can query them through a filter. Alternatively, query all of the products and then once that is returned, filter out the ones that have the proper taxonomy that you’re looking for.

Hope that helps,

  • Kyle G.

Thank you for reply to me!, maybe in the future, will be great an update with that as filter.