How could we get the products count for a specific query?

Cristina195
New Member
1 0 1

 

During the process of importing products from Shopify, we need to get the counter for active products. The '/products/count.json' returns the number of pages from Shopify, but without any restriction, we need an extra condition as: 'query=status:active'. For product retrieving we are using GraphQL (https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/product) and bring them page by page. Is there any way to count products before finishing the product import, in order to display the import progress? Thank you.

 

 

 query findProducts($cursor: String) {
    products(first: 50, after: $cursor, query: "status:active") {
      edges {
        cursor
        node {
          id
          title
          vendor
          handle
          variants(first: 1) {
            edges {
              node {
                price
              }
            }
          }
          images(first: 1) {
            edges {
              node {
                originalSrc
              }
            }
          }
        }
      }
      pageInfo {
        hasNextPage
      }
    }
  }