RequestBuilder

RequestBuilder

new RequestBuilder()

Nosto's Javascript API to interacting with the content delivery service.
Example
nostojs(api => {
  api
    .createRecommendationRequest()
    .setResponseMode("JSON_ORIGINAL")
    .enablePreview()
    .addElements(["frontpage-nosto-1"])
    .load()
    .then(response => {
      console.log(response);
    });
});

Methods

addCurrentCategories(categories) → {RequestBuilder}

Adds the given category names to the request. Any category name specified here are simply added to the request as personalisation filtering hints.
Parameters:
Name Type Description
categories Array.<String> the array of category ids

addCurrentCategoryIds(categoryIds) → {RequestBuilder}

Adds the given category ids to the request. Any category ids specified here are simply added to the request as personalisation filtering hints.
Parameters:
Name Type Description
categoryIds Array.<String> the array of category ids

addCurrentCustomFields(fields) → {RequestBuilder}

Adds the given current custom fields to the request. Any custom fields specified here are simply added to the request as personalisation filtering hints.
Parameters:
Name Type Description
fields Object custom field key-value pairs

addCurrentTags(tags) → {RequestBuilder}

Adds the given current tags to the request. Any tags (tags1, tags12, or tags13) specified here are simply added to the request as personalisation filtering hints.
Parameters:
Name Type Description
tags Array.<String> the array of tags

addCurrentVariation(variation) → {RequestBuilder}

Sets the current variation identifier for the session. A variation identifier identifies the current currency (or the current customer group). If your site uses multi-currency, you must provide the ISO code current currency being viewed.

It is not recommended to pass the variation identifier to an request builder but instead leverage the tagging.
Parameters:
Name Type Description
variation String the case-sensitive identifier of the current variation

addCustomer(customer) → {RequestBuilder}

Sets the information about the currently logged in customer. If the current customer is not provided, you will not be able to leverage features such as triggered emails. While it is recommended to always provide the details of the currently logged in customer, it may be omitted if there are concerns about privacy or compliance.

It is not recommended to pass the current customer details to the request builder but rather use the customer tagging.
Parameters:
Name Type Description
customer Customer

addElements(elements) → {RequestBuilder}

Adds the given elements (or placements) to the request. Any identifiers specified here are simply added to the elements already in the request.
Parameters:
Name Type Description
elements Array.<String> the array of placements
Example

To load data for a single placement

nostojs(api => api
  .createRecommendationRequest()
  .addElements('bestseller-home')
  .loadRecommendations());

addOrderData(order) → {RequestBuilder}

Adds the order object to the current request. This should be invoked only on the order confirmation page.
Parameters:
Name Type Description
order Order the details of the order that was placed

load(flags) → {Promise}

Builds the request and makes a request to Nosto.
Parameters:
Name Type Description
flags Object an object containing additional flags
Example

To load data for a single placement

nostojs(api => api
  .createRecommendationRequest()
  .addElements('bestseller-home')
  .load())
  .then((response) => console.log(response));

setCartContent(cart) → {RequestBuilder}

Adds the cart object to the current request. This should be preferably on every page load so as to keep the cart state as fresh as possible.
Parameters:
Name Type Description
cart Cart the details of the current shopping basket

setCoupon(coupon) → {RequestBuilder}

Parameters:
Name Type Description
coupon Coupon

setCurrentCategories(categories) → {RequestBuilder}

Sets the given category names to the request. Any category names specified here override the category names in the request.
Parameters:
Name Type Description
categories Array.<String> the array of category ids

setCurrentPriceFrom(value) → {RequestBuilder}

Sets the current lower price range to the request. Faceting needs to be enabled for the slot in order for this to function. Any lower value specified here are simply added to the request as personalisation filtering hints.
Parameters:
Name Type Description
value Number the lower range of the price

setCurrentPriceTo(value) → {RequestBuilder}

Sets the current upper price range to the request. Faceting needs to be enabled for the slot in order for this to function. Any upper value specified here are simply added to the request as personalisation filtering hints.
Parameters:
Name Type Description
value Number the upper range of the price

setCurrentTags(tags) → {RequestBuilder}

Sets the given current tags to the request. Any tags (tags1, tags12, or tags13) specified here are simply set to the request as personalisation filtering hints.
Parameters:
Name Type Description
tags Array.<String> the array of tags

setCustomer(customer) → {RequestBuilder}

Sets the information about the currently logged in customer. If the current customer is not provided, you will not be able to leverage features such as triggered emails. While it is recommended to always provide the details of the currently logged in customer, it may be omitted if there are concerns about privacy or compliance.

It is not recommended to pass the current customer details to the request builder but rather use the customer tagging.
Parameters:
Name Type Description
customer Customer the details of the currently logged in customer

setElements(elements) → {RequestBuilder}

Sets the given elements (or placements) to the request. Any identifiers specified here override all elements already in the request.
Parameters:
Name Type Description
elements Array.<String> the array of placements
Example

To load data for a single placement

nostojs(api => api
  .createRecommendationRequest()
  .setElements(['bestseller-home'])
  .loadRecommendations());

setPageType(pageType) → {Object}

Sets the identifier of the current page type to the current request. The different page types are product, front, search, cart, order, category, notfound and other.
Parameters:
Name Type Description
pageType String the current page type

setProducts(products, refopt) → {RequestBuilder}

Parameters:
Name Type Attributes Description
products Array.<Product>
ref String <optional>
the placement id that resulted in the product views

setResponseMode(mode) → {RequestBuilder}

Sets the response mode for the current request. The response mode can be used to switch between HTML and JSON. Here is an exhaustive list of the response modes. | Modes | Description | | -------------------- |:----------------------------------------------:| | HTML | HTML (SSR) | | JSON_170x170 | Raw JSON with 170x170px original aspect images | | JSON_100_X_100 | Raw JSON with 100x100px original aspect images | | JSON_90x70 | Raw JSON with 90x70px original aspect images | | JSON_50x50 | Raw JSON with 50x50px original aspect images | | JSON_30x30 | Raw JSON with 30x30px original aspect images | | JSON_100x140 | Raw JSON with 100x140px original aspect images | | JSON_200x200 | Raw JSON with 200x200px original aspect images | | JSON_400x400 | Raw JSON with 400x400px original aspect images | | JSON_750x750 | Raw JSON with 750x750px original aspect images | | JSON_10_MAX_SQUARE | Raw JSON with 100x100px center squared images | | JSON_200x200_SQUARE | Raw JSON with 200x200px center squared images | | JSON_400x400_SQUARE | Raw JSON with 400x400px center squared images | | JSON_750x750_SQUARE | Raw JSON with 750x750px center squared images | | JSON_ORIGINAL | Raw JSON with the original untouched images |
Parameters:
Name Type Description
mode String the response mode to be used
Sets the restore link for the current session. Restore links can be leveraged in email campaigns. Restore links allow the the user to restore the cart contents in a single click.

Read more about how to leverage the restore cart link

It is not recommended to pass the current restore link to the request builder but rather use the tagging approach.
Parameters:
Name Type Description
restoreLink

setSegmentCodes(segments) → {Object}

Sets the given list of manual segment identifiers to the current request. This method allows you explicitly associate the current customer with a segment.
Parameters:
Name Type Description
segments Array.<String> the list of force segment identifiers