Home > widget-integration > FilterAPI

FilterAPI class

API service for handling filter widget requests to the Boost filter engine.

This service provides functionality for fetching filtered product results from the Boost API. It manages request construction, caching, and response processing through extensible methods that allow customization for shop-specific requirements.

Signature:

export declare class FilterAPI extends BoostAPI 

Extends: BoostAPI

Remarks

Key features: - Automatic caching of filter responses - Query parameter building with locale and B2B support - Flexible response type handling (JSON/HTML) - Support for pagination and filtering - Extensible parameter and response processing

Example

Basic usage:

const api = new FilterAPI(store, helper, appService);
const response = await api.fetchAPI(
  '/collections/all',
  'product-list',
  {
    additionParams: { page: 1, limit: 20 },
    responseType: 'json'
  }
);

Constructors

Constructor

Modifiers

Description

(constructor)(store, helper, platformLoader, appService, b2bService)

Creates a new FilterAPI instance with injected dependencies

Properties

Property

Modifiers

Type

Description

appService

protected

AppService

b2bService

protected

B2BService

helper

protected

FilterHelper

platformLoader

protected

PlatformLoader

store

protected

FilterStore

Methods

Method

Modifiers

Description

addAndConditionFlags(params)

protected

Adds AND condition flags for filter options that require it.

Checks filter options in state for useAndCondition flag and adds corresponding _and_condition parameters. This allows multiple filter values within the same option to use AND logic instead of OR logic (e.g., products must have BOTH tags). Override to customize AND condition logic or add custom boolean operators.

addCollectionScope(params)

protected

Adds collection scope and tag parameters from app configuration.

Includes collection_id and associated tags from general settings when filtering within a specific collection context. Override to customize collection scoping or add additional collection-based parameters.

addCustomerParams(params)

protected

Adds customer identification and session tracking parameters to API request.

Includes customer ID (if logged in) and marks the request as not a first load. The API uses customer ID for personalization. Override to add custom customer attributes or implement shop-specific customer tracking.

addCustomParams(queryParams)

protected

Adds custom parameters from global configuration.

This method reads custom parameters from window.boostSdCustomParams or window.boostWidgetIntegration.config.customization.filter.customizedAPIParams and adds them to the API request. Override this method to add shop-specific custom parameters or modify parameter handling logic.

addDeviceParams(params)

protected

Adds device type and viewport parameters to API request.

Detects the current device type (mobile/tablet) based on viewport width and includes this information in the API request. The API uses this to return device-appropriate responses. Override to customize device detection logic or add additional device-specific parameters.

addFilterFlag(params, filteredParams)

protected

Adds or removes filter flag based on presence of filter parameters.

Checks if any filter parameters (those starting with 'pf_') exist and adds a filter: true flag to indicate filters are active. If no filter params exist, removes the filter flag. This helps the API optimize query execution. Override to customize filter flag logic.

addPaginationParams(params)

protected

Adds pagination parameters from filter state to API request params.

Extracts the current page number from FilterStore pagination state and includes it in the API request. Override to customize pagination behavior or implement infinite scroll patterns.

addSearchQueryParam(params)

protected

addShowFilterTreeParam(params)

protected

Adds showFilterTree parameter based on filter toggle button state.

Checks the filter toggle button state in FilterStore and includes showFilterTree flag if the filter tree should be displayed. This is used for mobile/off-canvas filter layouts. Override to customize filter tree visibility logic.

addSortParams(params)

protected

Adds sorting parameters from filter state to API request params.

Extracts the sort value from FilterStore state and includes it in the API request. Override this method to customize sorting behavior, add custom sort options, or implement shop-specific sorting rules.

applyFilterSettings(queryParams)

protected

Applies filter-specific settings to query parameters.

This method applies shop configuration settings such as sorting behavior, out-of-stock display options, and availability filtering. Override this method to customize filter settings based on shop-specific requirements.

buildFilterQueryParams(params)

protected

Protected method for building query parameters - can be overridden for customization

buildParams(additionParams, modifyParams)

protected

buildSearchPageParams(additionParams, modifyParams)

Builds parameters for the API request from store state and additional params. Uses a functional pipeline approach to transform parameters through multiple stages.

This method orchestrates the entire parameter building process by applying transformations for sorting, pagination, device detection, customer data, filters, and shop-specific settings. Override this method to customize the parameter building pipeline for shop-specific requirements.

clearCache()

Clears all cached data

fetchAPI(url, addition)

Main method to fetch filter API data with caching support

getLatestRequestKey()

Gets the latest request cache key

getTemplateParsedById(templateId)

protected

Gets template parsed by ID from app configuration.

This method resolves a template by its ID from the TAE app configuration, checking both templateParsed and template properties. Override this method to customize template resolution logic or provide custom templates for specific shops.

handleBannerParams(params)

protected

Adds banner interleaving parameter if feature is enabled.

Checks template metadata for banner interleaving feature flag and includes insert_banners parameter if enabled. This tells the API to include promotional banner content in the product results. Override to customize banner insertion logic.

handleCurrencyMetadata(meta)

protected

Handles currency metadata from API response.

This method updates shop currency settings (money_format, money_format_with_currency, currency) based on metadata returned from the API. Override this method to customize currency handling or apply shop-specific currency transformations.

handleTagParams(params)

protected

Transforms pf_tag parameter to standard tag parameter format.

Renames the filter-specific pf_tag parameter to the standard tag parameter expected by the API. This normalization ensures consistent tag handling across different contexts. Override to customize tag parameter transformation.

handleVendorPage(params)

protected

Adds vendor parameter when on a vendor-specific page.

Detects if the current page is a vendor page and extracts the vendor name from the URL query parameter 'q', then includes it in the API request. Override to customize vendor detection or add vendor-specific parameters.

makeAPIRequest(url, queryParams, responseType)

protected

Makes the actual API request to fetch filter data.

This method handles both template-based rendering (when widgetId is provided) and standard JSON/HTML responses. It performs the HTTP request, processes the response data, and handles currency metadata. Override this method to customize request behavior such as adding authentication, custom headers, or implementing retry logic.

mergeAdditionalParams(params, additionParams)

protected

Merges additional parameters provided by caller into the parameter object.

Combines any extra parameters passed to fetchAPI() with the base parameters built from filter state. Additional params take precedence over base params. Override to validate, transform, or filter additional parameters.