Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Method Objective

The method returns an API response when requesting product recommendations.

Syntax and parameters

Code Block
themeFadeToGrey
pcsdk.recommend(code, params).then(success).catch(error)


NameTypeRequirementDescription
codestringrequiredUnique code of the recommendation block. See this value in the "data-recommender-code" attribute of the block created in PersonaClick account.
paramsobjectrequiredObject with request parameters.
successfunctionrequiredA callback function, to which the API response will be passed. Response type: object.
errorfunctionoptionallyA callback function that will be called when an error occurs (any HTTP status code other than 200).

Request parameters

NameTypeRequirementDescription
itemnumber/stringrequired in some casesProduct ID. This  This parameter is mandatory for the requests of blocks with algorithms that use the algorithms "Similar" and "Also bought"depend on the current product. Algorithms: "Similar", "Products usually purchased with this product", "Store recommendations", etc.
excludearrayoptionallyProduct IDs array, which should be excluded from the recommended products list.
categorynumber/stringrequired in some casesCategory ID. This parameter is mandatory for all blocks set on category pages.
search_querystringrequired in some casesThe text of the search query. This parameter is mandatory for the requests of blocks that use the "Search" algorithm.
limitnumberoptionallyA maximum number of products in the API response.
locationsarrayoptionallyArray with location IDs. If used, the API response will return products available in the listed locations.
brandsarrayoptionallyArray with brand names. If used, only the products of the listed brands will be returned in the API response.
exclude_brandsarrayoptionallyArray with brand names. If used, the API response will exclude the products of the listed brands.
categoriesarrayoptionallyArray with category IDs. If used, the API response will only return products that are included in the listed categories.
discountbooleanoptionallyIf used with "true" value, then only those products, the value of which is less than the "oldprice" value, will be returned in the API response.

API response properties

NameTypeDescription
htmlstringHTML-code of the block with products. The template is customized in the PersonaClick account.
titlestringThe block title. Corresponds to the value of the "Action" element in the block rules.
recommendsarrayArray with product IDs.
idnumberUnique block identifier. Corresponds to the block ID in the list of blocks in the PersonaClick account.
snippetstringJS snippet code attached to the recommender.

Examples of use

For blocks with algorithms that require the "Product ID":

Code Block
languagejs
themeFadeToGrey
pcsdk.recommend("1fd1b3495137bc3c9299816026acf36f", {item: 100500})
    .then((response) => {
        // the functionality of rendering a block of product recommendations
    })
    .catch((error) => {
        // when something went wrong
    });


For blocks with algorithms that require the "Category ID":

Code Block
languagejs
themeFadeToGrey
pcsdk.recommend("1fd1b3495137bc3c9299816026acf36f", {category: 146})
    .then((response) => {
        // the functionality of rendering a block of product recommendations
    })
    .catch((error) => {
        // when something went wrong
    });


For blocks with an algorithm that requires the "Search Query":

Code Block
languagejs
themeFadeToGrey
pcsdk.recommend("1fd1b3495137bc3c9299816026acf36f", {search_query: "To be or not to be"})
    .then((response) => {
        // the functionality of rendering a block of product recommendations
    })
    .catch((error) => {
        // when something went wrong
    });


Full example:

Code Block
languagejs
themeFadeToGrey
pcsdk.recommend("1fd1b3495137bc3c9299816026acf36f", {
    item: 100500, 
    exclude: [3, 14, 159, 26535], 
    category: 146, 
    search_query: "To be or not to be", 
    limit: 15, 
    brands: ["Alas", "poor", "Yorick"], 
    categories: [1, 146, 100500]
})
    .then((response) => {
        // the functionality of rendering a block of product recommendations
    })
    .catch((error) => {
        // when something went wrong
    });



Column

Page Navigation

Table of Contents
maxLevel3
indent0px
stylenone




Related Pages

Filter by label (Content by label)
showLabelsfalse
showSpacefalse
sorttitle
cqllabel = "recommenders"