Introduction

 

Developer Preview
APIs in Developer Preview are subject to change and are not intended for use in production.
Send us your suggestions for improving these functions. Your feedback is valuable to us.

 

The Recommendations API allows you to promote and recommend items to your customers. You can get item recommendations from catalogs on your site using algorithms provided by apps.

Note: Currently, the Recommendations API is for use with Wix Stores only.

With the Recommendations API, you can:

Algorithms

Algorithms are programs that identify and return a set of item recommendations based on a catalog. There are different types of algorithms, identified by their algorithmType that calculate different kinds of recommendations. For example, Algorithms with the RELATED_ITEMS algorithmType also take a list of items as input and use those to calculate recommendations.

For example, Wix Stores provides the following algorithms:

NameDescriptionAlgorithm Type
“From the same categories”Returns items that share the most categories with items in the list provided.RELATED_ITEMS
“Frequently bought together”Returns items that are frequently bought together with the first item in the list provided.RELATED_ITEMS
“Frequently viewed together”Returns items that are frequently viewed together with the first item in the list provided.RELATED_ITEMS
“Best sellers”Returns the items from the catalog with the highest number of sales.GLOBAL

Tip: If you want to display item recommendations on your site, you can use the Wix Stores “Slider Product Gallery” and “Related Products” elements. These elements use Recommendations API functionality without the need for manual coding. In these elements' settings, you can choose which algorithm to use from among those available on your site.

On your Product, Cart, and Thankyou pages you can use RELATED_ITEMS type algorithms to get recommendations related to the product/s shown on the page. On other pages, you can get recommendations from GLOBAL type algorithms.

Before you begin

  • You must have a Wix app that provides algorithms installed on your site, and you must have a Wix app whose catalogs are supported by those algorithms installed on your site. For more information see listAvailableAlgorithms(). Currently, the only app providing algorithms and their supported catalogs is Wix Stores.
  • No caching is implemented, so repeat calls take the same time to complete as the first call.

We To use the Recommendations API, import { recommendations } from wix-ecom-backend:

Copy
import { recommendations } from "wix-ecom-backend";

Use cases

Send emails to customers recommending related products.

Terminology

  • Catalog: A set of products or services available for purchase in a Wix app. For example, a set of products in Wix Stores.
  • Algorithm: A program implemented by a Wix app, such as Wix Stores, which returns a list of item recommendations.

Permissions information

Functions in the Recommendations API are restricted and only run if you elevate permissions using the wix-auth elevate() function.

Warning: Elevating a function allows it to be called by any site visitor. Exercise caution to prevent security vulnerabilities.

Did this help?

getRecommendation( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

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

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.
Permissions
Read eCommerce - all read permissions
Learn more about app permissions.
Method Declaration
Copy
function getRecommendation(
  algorithms: Array<Algorithm>,
  options: GetRecommendationOptions,
): Promise<GetRecommendationResponse>;
Method Parameters
algorithmsArray<Algorithm>Required

A list of algorithms checked in a specific order determined by their appID and their position in the algorithms array. See the method description for more information.

If no algorithm is able to return at least minimumRecommendedItems items, an empty array is returned.


optionsGetRecommendationOptions

Get recommendation options.

Returns
Return Type:Promise<GetRecommendationResponse>
Get recommendation with algorithms and options objects
JavaScript
/************************************** * Backend code - recommendations.web.js * *************************************/ import { Permissions, webMethod } from "wix-web-module"; import { recommendations } from "wix-ecom-backend"; export const getRecommendation = webMethod( Permissions.Anyone, async (algorithms, options) => { try { const result = await recommendations.getRecommendation( algorithms, options, ); return result; } catch (error) { console.error(error); // Handle the error } }, ); /************* * Page code * ************/ import { getRecommendation } from "backend/recommendations.web"; $w.onReady(async function () { let algorithm = { appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e", id: "68ebce04-b96a-4c52-9329-08fc9d8c1253", }; let item = { appId: "215238eb-22a5-4c36-9e7b-e7c08025e04e", catalogItemId: "11e2ffb7-2520-3c21-051e-1f05486b9061", }; let options = { items: [item], minimumRecommendedItems: 1, }; let recommendations = await getRecommendation([algorithm], options); console.log(recommendations); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?

listAvailableAlgorithms( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Returns a list of recommendation algorithms that can be used on your Wix site or project. These algorithms can be used with getRecommendation() to provide item recommendations to the customer.

Algorithms are run by the apps that provide them, and can only be used on catalogs they support. Apps may provide algorithms for use with their own catalogs and/or catalogs from other apps.

The app which provides an algorithm is referenced by that algorithm’s appId. The apps whose catalogs are supported by an algorithm are referenced by the IDs in that algorithm’s catalogAppIds array.

For an algorithm to be considered “Available” and returned in this method’s response, the algorithm must meet the following conditions:

  1. The algorithm’s appId must match the ID of an installed Wix app.
  2. At least 1 of the IDs in catalogAppIds must match the ID of an installed Wix app.

Wix app IDs are listed here.

Permissions
Read eCommerce - all read permissions
Learn more about app permissions.
Method Declaration
Copy
function listAvailableAlgorithms(): Promise<ListAvailableAlgorithmsResponse>;
Request
This method does not take any parameters
Returns
Return Type:Promise<ListAvailableAlgorithmsResponse>
JavaScript
import { recommendations } from "wix-ecom-backend"; async function listAvailableAlgorithms() { try { const result = await recommendations.listAvailableAlgorithms(); return result; } catch (error) { console.error(error); // Handle the error } }
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?