Lab - Create a Search and Filter Flow in Postman
Lab - Create a Search and Filter Flow in Postman
Lab - Create a Search and Filter Flow in Postman
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 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:
In order to support this flow, you’ll need a pool of at least four products following these guidelines:
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.
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:
v3_token, store_hash, storefront_channel_id and private_storefront_token.private_storefront_token (Postman sends server-to-server requests, so the Private Token is used; the Storefront token is for browser use only).private_storefront_token when run.filter_search_term with the search term that will capture your chosen products as the value.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.
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.
filter_category variable 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.)
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.
You should observe a smaller product results set than in the previous request.
Replace the value of variantFilterName (“Color” in the above code) with the exact name of the variant option you want to filter on.
Just as with category, you’ll find and store the first available value for your chosen variant option.
filter_variant_attr_name and filter_variant_attr_val are populated on the collection.
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.