Home > widget-integration > FilterAPI > makeAPIRequest
FilterAPI.makeAPIRequest() method
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.
Signature:
protected makeAPIRequest(url: string, queryParams: URLSearchParams, responseType: "json" | "html"): Promise<FilterAPIResponse | null>;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
url |
string |
API endpoint URL to fetch filter data from |
|
queryParams |
URLSearchParams |
Query parameters to include in the request |
|
responseType |
"json" | "html" |
Expected response type ('json' or 'html') |
Returns:
Promise<FilterAPIResponse | null>
Promise resolving to API response data, or null if request fails
Example
Extend to add custom authentication headers:
window.boostWidgetIntegration.extend('FilterAPI', (FilterAPI) => {
return class CustomFilterAPI extends FilterAPI {
protected async makeAPIRequest(url, queryParams, responseType) {
// Add shop-specific authentication token
const widgetId = queryParams.get('widgetId');
const template = widgetId ? this.getTemplateParsedById(widgetId) : null;
if (template && typeof template === 'string') {
queryParams.delete('widgetId');
const response = await fetch(`${url}?${queryParams.toString()}`, {
method: 'GET',
headers: {
'X-Shop-Token': this.getShopAuthToken()
}
});
// Handle response...
}
return super.makeAPIRequest(url, queryParams, responseType);
}
};
});