Home > widget-integration > FilterService > fetchFilters

FilterService.fetchFilters() method

Fetches filter results from the API with optional additional parameters.

Main method for requesting filtered product data. Handles API calls, request ID tracking, and action type storage for analytics. Supports various addition parameters like pagination behavior and collection focus.

Signature:

fetchFilters(addition?: FilterAPIAdditionParams): Promise<string | FilterAPIResponse | null>;

Parameters

Parameter

Type

Description

addition

FilterAPIAdditionParams

(Optional) Additional API request parameters

Returns:

Promise<string | FilterAPIResponse | null>

Promise resolving to API response or error string

Remarks

Automatically saves request ID and action type to localStorage for analytics tracking. The request ID is used to correlate user actions with API requests.

Example

Override to add shop-specific request headers:

async fetchFilters(addition = {}) {
  // Add custom parameters for shop
  const customAddition = {
    ...addition,
    shopMetadata: {
      segment: this.getCustomerSegment(),
      locale: this.getCurrentLocale()
    }
  };
  return super.fetchFilters(customAddition);
}