Build UI
Modify Request

Overview

7min

Modify Request

To modify a search request, the outgoing query to the indexed catalog is intercepted and any of the available Klevu API parameters are available to be inserted, or adjusted as needed.

There are two steps:

  1. Reference the API to understand what parameters are available to meet the objective
  2. Attach the override to the appropriate outgoing query (or queries)



API Referencing

Any of the Klevu API parameters are available to be applied as needed or otherwise to override any default values.

For example, the following snippet of an outgoing productList API Request assigns the value of "10" as the number of filter options to return.

recordQueries: [ { filters: { filtersToReturn: { options: { limit: 10 } } }, id: "productList", typeOfRequest: "SEARCH", settings: { query: { term: "jackets" } } } ],

See : Klevu API documentation on Retrieving Filters for more details and options

Attaching the Override

The query parameters are directly added or replaced by using the klevu.modifyRequest function.

klevu.modifyRequest("<scope>", "<parameter object>", "<parameter value>");

The parameter object notation corresponds to that used in the outgoing JSON API query

For example, the following example snippet modifies the outgoing productList API Query by assigning the value of "20" as the number of filter options to return.

klevu.modifyRequest("landing", "productList.filters.filtersToReturn.options.limit", 20 );

The following full object notation syntax is also acceptable.

klevu.modifyRequest("landing","productList", { filters: { filtersToReturn: { options: { limit: 20 } } } });

Advanced data objects or modules can be accessed using a callback function as the parameter object

klevu.modifyRequest("landing", function(data, scope){ console.log('modifyRequest data',data); });



Determining Scope

Note that each klevu.modifyRequest function requires definition within the corresponding scope of the override. We will chart these below.

Scope

Description

all

Applies to all scope modules

quick

QuickSearch module

landing

SRLP module

catnav

Category module

full_page

Both SRLP and Category modules (same as "landing,catnav")

Multiple klevu.modifyRequest functions can be applied in the same or mixed scope.



Examples

Please see the Modify Request Examples section for details of common uses.





.

Updated 30 Oct 2023
Doc contributor
Doc contributor
Doc contributor
Did this page help you?