Home > widget-integration > RecommendationAPI

RecommendationAPI class

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

This service extends to provide specialized functionality for fetching product recommendations from the Boost API. It manages request construction through extensible protected methods that allow Technical Support teams to customize query parameters and body payloads for shop-specific requirements.

The service uses a functional pipeline approach to transform request parameters, applying currency settings and B2B configurations automatically while allowing additional customizations through method overrides.

Signature:

export declare class RecommendationAPI extends BoostAPI 

Extends: BoostAPI

Remarks

Key extensibility features: - Protected methods for query parameter and body payload customization - Automatic currency and B2B parameter injection - Functional composition pipeline for parameter transformation - Inherits all HTTP client capabilities from

Performance considerations: - Uses functional pipes for efficient parameter transformation - Minimal overhead for parameter building - Leverages inherited HTTP client connection pooling

Technical Support teams can extend this service to: - Add shop-specific query parameters (pricing tiers, customer segments) - Modify request body payloads with custom filters or context - Implement request/response transformations - Add custom error handling or retry logic - Integrate shop-specific analytics or tracking

Example 1

Basic usage in a recommendation widget:

const api = new RecommendationAPI(platformLoader, appService, b2bService);
const response = await api.getRecommendation(
  { limit: 10, page: 1 },
  { productId: '12345', type: 'similar' }
);

Example 2

Extend to add custom query parameters for VIP customers:

window.boostWidgetIntegration.extend('RecommendationAPI', (RecommendationAPI) => {
  return class CustomRecommendationAPI extends RecommendationAPI {
    protected buildRecommendationQueryParams(params) {
      const enhanced = super.buildRecommendationQueryParams(params);

      // Add VIP pricing tier for wholesale customers
      const customer = this.platformLoader.platform.customer;
      if (customer?.tags?.includes('wholesale')) {
        enhanced.pricing_tier = 'wholesale';
        enhanced.discount_level = 'tier-1';
      }

      return enhanced;
    }
  };
});

Example 3

Extend to add custom filtering to request body:

window.boostWidgetIntegration.extend('RecommendationAPI', (RecommendationAPI) => {
  return class CustomRecommendationAPI extends RecommendationAPI {
    protected buildRecommendationBodyPayload(bodyPayload) {
      const enhanced = super.buildRecommendationBodyPayload(bodyPayload);

      // Exclude out-of-stock and discontinued products
      enhanced.filters = {
        ...enhanced.filters,
        excludeTags: ['out-of-stock', 'discontinued'],
        inStock: true
      };

      // Add customer segment for personalization
      enhanced.customerSegment = this.getCustomerSegment();

      return enhanced;
    }

    getCustomerSegment() {
      const customer = this.platformLoader.platform.customer;
      if (customer?.ordersCount > 10) return 'loyal';
      if (customer?.ordersCount > 0) return 'returning';
      return 'new';
    }
  };
});

Constructors

Constructor

Modifiers

Description

(constructor)(platformLoader, appService, b2bService)

Creates a new RecommendationAPI instance with injected dependencies.

Initializes the API client by configuring the base URL from the application configuration and setting up the HTTP client through the parent class. All dependencies are automatically injected by the dependency injection framework.

Methods

Method

Modifiers

Description

buildRecommendationBodyPayload(bodyPayload)

protected

Builds and enhances the request body payload for recommendation API requests.

This method provides an extension point for modifying the recommendation request body before it's sent to the API. The default implementation returns the payload unchanged, serving as a pass-through that allows Technical Support teams to intercept and enhance the payload with shop-specific data, filters, or context.

Unlike query parameters (which are URL-based), the body payload contains the core recommendation context like product IDs, widget configuration, and customer data that determines which products to recommend.

buildRecommendationQueryParams(params)

protected

Builds and enhances query parameters for recommendation API requests.

This method transforms the base query parameters through a functional pipeline that automatically adds currency information and B2B-specific parameters. It serves as a key extension point for Technical Support teams to inject shop-specific query parameters without modifying the core request flow.

The method uses functional composition (pipe) to apply transformations sequentially, ensuring each enhancement step is clearly separated and maintainable.

getRecommendation(params, bodyPayload)

Fetches product recommendations from the Boost recommendation API.

This is the main entry point for making recommendation requests. It orchestrates the request construction process by delegating to extensible protected methods for parameter and payload building, then executes the HTTP POST request to the recommendation endpoint.

The method follows a clear pipeline: 1. Enhances query parameters through 2. Enhances request body through 3. Serializes parameters to query string format 4. Executes POST request with enhanced parameters and body