Best way to get all product types from a search

Solved
Highlighted

What is the best way to return all of the product types from the performed search. The search could have over 300 items

0 Likes
Highlighted

Im thinking of using the API to get all product using search query, loop through the pages and store all product types

0 Likes
Highlighted
Excursionist
10 4 4

This is an accepted solution.

You can use GraphQL Bulk Operations to retrieve big chunks of data. This query for example will extract the info you require:

mutation {
  bulkOperationRunQuery(
   query: """
    {
      products {
        edges {
          node {
            id
            title
            handle
            productType
          }
        }
      }
    }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

You'll need to do some polling to check if the operation is completed, and then parsing the result line by line (jsonl)

https://shopify.dev/tutorials/perform-bulk-operations-with-admin-api

This way Shopify will handle all the load and you won't need to paginate. Cheers!

1 Like