Appearance
Product Category Search with our JS SDK
Our SDK helps making requests against our API eaiser for you. It works both with strongly-typed TypeScript and with JavaScript. You can also use it direcly via a CDN provider. Read more about that here. If you do use it directly from a CDN, then all of our types are namespaced with a Relewise.
-prefix. So to get the searcher you need to write new Relewise.Searcher()
instead of new Searcher()
.
Before going any further, make sure you have read the following:
- Read about how to authenticate against our API here.
- Read about handling different types of users here.
The following shows an example on how to perform a product category search with an assortment filter.
ts
const settings = {
language: 'da-DK',
currency: 'DKK',
displayedAtLocation: 'Search Page',
user: UserFactory.anonymous()
};
const builder = new ProductCategorySearchBuilder(settings)
.setSelectedCategoryProperties({
displayName: true,
paths: true,
dataKeys: ['Description', 'ImagePath']
})
.setTerm('shoe')
.pagination(p => p
.setPageSize(30)
.setPage(1))
.filters(f => f
.addProductCategoryAssortmentFilter(1),
);
const searcher = new Searcher(RELEWISE_DATASET_ID, RELEWISE_API_KEY, {
serverUrl: RELEWISE_SERVER_URL,
});
searcher.searchProductCategories(builder.build());
By using setSelectedCategoryProperties
it is possible to select the specific properties, from Relewise, that you need for rendering a category tile, list etc. That way we can store fields that are needed for e.g. filtering or Merchandising, but which might not be needed when rendering the actual product. This allows us to reduce the payload on the HTTP responses, by only returning a minimum set of necessary information.