Lab - Create a Search and Filter Flow in Postman
Introduction
In this lab, you’ll utilize the environment configuration you’ve already created in Postman to create a series of request that will progressively filter a product search query.
Certain catalog data must be present in your BigCommerce store in order for the exercise queries to succeed. We’ll detail the requirements below.
In this lab, you will:
- Create a series of queries to filter product results
Prerequisites
- A BigCommerce sandbox store or trial store, or a full production store
- Postman
- Products and categories with configuration according to the guidelines below
Catalog Data Prerequisites
In the requests you’ll be creating, you’ll be starting out querying for products on a specific search term, then capturing and applying other available filters to continue narrowing the results set. We’ll be filtering on these facets:
- A top-level category
- A variant option value
In order to support this flow, you’ll need a pool of at least four products following these guidelines:
- All products must include the same search term in their name.
- Various products should be assigned to the same top-level categories.
- All products must include a variant option with the same name.
- Various values for the variant option should be shared among different products, but not all products.
The common category assignments and values between products should allow for varied results sets depending on what filters are applied. Below is an example product set.
In your Product Filters settings in the BigCommerce control panel, make sure the Category and Variant options are enabled as visible filters at the global or channel level.
Postman Recap
This lab will not require any of the collection variables captured by requests in the previous exercise, but it’s necessary that the following still be in place:
- An environment with variables set for
v3_token,store_hash,storefront_channel_idandprivate_token(and optionallystorefront_tokenfrom the browser-token request). - A collection with Bearer Token authentication using the value of
private_token(Postman sends server-to-server requests, so the Private Token is used; the Storefront token is for browser use only). - A “REST Create Private Token (server-to-server)” request that will populate
private_tokenwhen run.
Create a Search Request
Step 1: Create the Request
- In the Variables tab of your collection, create a variable named
filter_search_termwith the search term that will capture your chosen products as the value. - Create a new “GQL Product Search” HTTP request and save it to your collection. This request requires the following details.
- In the Headers tab, select your GraphQL headers preset to apply “Accept” and “Content-Type” headers.
- Enter the following query in the Body tab:
- Enter the following in the GraphQL Variables section of the Body tab:
- Send the request and observe the response.
The search response should include the products that match your search term, and the fields included should make it easy to predict which products will continue to be included in the set as you continue to narrow it with filters.
The data.site.search.searchProducts.filters data should also enumerate the available filter values that can be applied to the product results.
Step 2: Add Tests
- Enter the following “Post-response” value in the Scripts tab:
- Send the request again and verify that all tests are successful.
Step 3: Store a Category Filter
The tests you’ve put in place confirm that at least one available category filter is present in the response. Let’s add code to capture the first available filter value in a collection variable to use in the next request.
- Add the following after the previous code in Scripts:
- Send the request again and verify that the
filter_categoryvariable is populated in your collection with the ID of a category.
If you want a different category value than the first to be used to further filter the results, update the filterValueIndex value in the Tests code. (The value is zero-based, so it should be off-set by one compared to the position of the desired value in the filter list.)
Narrow Search Results by Category
You’ll now create a request that is identical to the previous one, but adding a filter on the category ID to the query. The easiest way to do this in Postman is to duplicate the request initially.
Step 1: Create the Request
- Duplicate the request “GQL Product Search” in the collection and rename the new request “GQL Product Search - Cat.”
- Clear the contents of the Tests tab.
- In the Body, update the variables and filter arguments in the query as follows:
- Update the GraphQL Variables section of the Body tab:
- Send the request and observe the results.
You should observe a smaller product results set than in the previous request.
Step 2: Add Tests
- Enter the following “Post-response” value in the Scripts tab:
Replace the value of variantFilterName (“Color” in the above code) with the exact name of the variant option you want to filter on.
- Send the request again and verify that tests are successful.
Step 3: Store a Variant Filter
Just as with category, you’ll find and store the first available value for your chosen variant option.
- Add the following after the previous code in Scripts:
- Send the request again and verify that values for
filter_variant_attr_nameandfilter_variant_attr_valare populated on the collection.

Narrow Search Results By Variant Value
Step 1: Create the Request
- Duplicate the request “GQL Product Search - Cat” in the collection and rename the new request “GQL Product Search - Cat, Variant”.
- Clear the contents of the Tests tab.
- In the Body, update the variables and filter arguments in the query as follows:
- Update the GraphQL Variables section of the Body tab:
- Send the request and observe the results.
This time, in addition to your (hopefully) narrowed results set, you should also be able to observe that the isSelected field is true for the variant filter that was captured and applied.
Step 2: Add Tests
- Enter the following “Post-response” value in the Scripts tab:
- Send the request again and verify that all tests are successful.