Search.../

getRecommendation( )

Developer Preview

Returns a recommendation object containing a list of items to recommend to the customer.

Description

getRecommendation() determines which items to recommend based on the given recommendation algorithms.

getRecommendation() doesn’t run the algorithms. It calls the installed apps that provide them.

Apps may provide algorithms for use with their own catalogs, or for use with catalogs from other apps. For example, Wix Stores provides algorithms that can only be used on its own catalogs. To run an algorithm, the app providing it must be installed, and an app providing a supported catalog must be installed. For more information and to see which algorithms are available on your site or project, call listAvailableAlgorithms().

getRecommendation() operates as follows:

  1. getRecommendation() receives as input a list of algorithms as an array. These algorithms can be provided by different apps and can apply to different catalogs.
  2. getRecommendation() calls the app that corresponds to the appId of the first algorithm in the list of algorithms. It passes that algorithm’s ID and the IDs of any subsequent algorithms in the array for the same app.
  3. The app runs the algorithms.
  4. getRecommendation() returns items recommendations from the first algorithm (according to its position in the algorithms array) that meets the minimum number of recommendations. At that point getRecommendation() stops calling other apps.
  5. If none of the algorithms run by the first app meet the minimum recommended items, getRecommendation() finds the next algorithm in the array with a new appId (an ID of an app that has not yet been called), and repeats the process.
  6. If no algorithms in the algorithms array recommend at least the minimum recommended items, getRecommendation() returns an empty array.

Authorization

Request

This endpoint does not take any parameters

Response Object

NAME
TYPE
DESCRIPTION
recommendation
Recommendation

An object containing a list of items recommended by 1 of the specified algorithms. The recommendation is empty if none of the specified algorithms recommended enough items.

Status/Error Codes

Was this helpful?

Get recommendation with algorithms and options objects

Copy Code
1/**************************************
2 * Backend code - recommendations.web.js *
3 *************************************/
4import { Permissions, webMethod } from 'wix-web-module';
5import { recommendations } from 'wix-ecom-backend';
6
7export const getRecommendation = webMethod(Permissions.Anyone, async (algorithms, options) => {
8 try {
9 const result = await recommendations.getRecommendation(algorithms, options);
10
11 return result;
12 } catch (error) {
13 console.error(error);
14 // Handle the error
15 }
16});
17
18/*************
19 * Page code *
20 ************/
21
22
23import { getRecommendation } from 'backend/recommendations.web';
24
25$w.onReady(async function () {
26 let algorithm = {
27 appId: '215238eb-22a5-4c36-9e7b-e7c08025e04e',
28 id: '68ebce04-b96a-4c52-9329-08fc9d8c1253'
29 };
30 let item = {
31 appId: '215238eb-22a5-4c36-9e7b-e7c08025e04e',
32 catalogItemId: '11e2ffb7-2520-3c21-051e-1f05486b9061'
33 };
34 let options = {
35 items: [item],
36 minimumRecommendedItems: 1
37 }
38 let recommendations = await getRecommendation([algorithm], options);
39 console.log(recommendations);
40});
41