How to set facets on their keys/ids, not on their values?
What is the deal?
As indicated in the Narrative API request documentation (here), by default, you can set the selected value of a facet based on its (potentially localized) value.
But, this might not be efficient for the following reasons:
You might not want to expose the localized value in the URL after the user selects a facet (either because it is a different value in each language, or because it’s not seo friendly, or because this is not the way your e-shop system works)
In order to create your API request you might not want to retrieve the localized value of the selected facet from it’s key or id from the URL (for performance or maintainability reasons)
In any case, have no fear, this option is fully supported by Boxalino :)
Pre-requisite: send us the required data
In order to set a user selected facet with its key or its id (and not with its (localized) value), you need to first make sure you provided the required key/id data in your doc_attribute_value data or in your admin configuration (find more information on how to do that here).
In this article we will assume that you have already done so and that you have waited for the daily synchronization process to have taken and updated your data after a full production (or dev) product sync.
How to send the your request
As indicated in the Narrative API request documentation (here), you can add an extra parameter “valueKey” to your facet request as here
{
"field":"brand",
"values":["123", "456"],
"valueKey":"id"
}
You can do it typically either on “id” or “key” (as per the indicated parameters here).
It is advised to use the ‘id’ to indicate the value of the internal id of a facet value and ‘key’ as the url encoded value which you expose to the user when a facet value is selected.
By defining the parmaeter ‘valueKey’, you can then simply indicate the related id/key values in the “values” parameter instead of the (possibly localized) field values which are used otherwise by default.