The XRecommend service lets you fetch AI-driven product recommendations either for multiple slots at once or for a single slot, using context and merchandising rules to tailor results for each shopper.
Methods
// Returns a recommendation response mapped by element IDs.
xg.recommend.getResults({ elementIds: ['<element_id_1>', '<element_id_2>'], options: { pathname: '/en-us/' } });
// Returns a recommendation response for the given element ID.
xg.recommend.getResultsById({ elementId: '<element_id>', options: { pathname: '/en-us/' } });
// Returns a container response for the given container IDs.
xg.recommend.getResults({ containerIds: ['<container_id_1>', '<container_id_2>'], options: { pathname: '/en-us/', version: 'v3' } });
// Returns a container response for the given element ID.
xg.recommend.getResultsById({ containerId: '<container_id>', options: { pathname: '/en-us/', version: 'v3' } });getResults
getResults
Description: Fetches recommendation results for multiple elements at once.
Think of an “element” as a recommendation slot, like “You May Also Like” on a product page or “Trending Now” on your homepage.Gets recommendation results by a list of elementIds.
Parameters
Name | Type | Required | Description |
|
| ✅ (for v2) | The IDs of the elements that you want to fetch results for |
|
| ✅ (for v3) | The IDs of the containers that you want to fetch results for |
↳ |
| ❌ | The version of the API to use. v2 corresponds with the experience api, while v3 corresponds with the containers api. |
↳ |
| ❌ | The pathname that includes the locale (default to 'default' locale) |
↳ |
| ❌ | The query string of the url |
↳ |
| ❌ | The locale to get items from |
↳ |
| ❌ | Product codes to exclude from the recommendations separated by |
↳ |
| ❌ | Product codes of recently viewed items separated by |
↳ |
| ❌ | Product code of the currently viewed product on a PDP page. Used to enhance recommendations. |
↳ |
| ❌ | Product code of the target product (used for passing a product code for anything other than a PDP page) |
↳ |
| ❌ | Context object used for dynamic filtering |
|
| ❌ | An optional queryId passed to cancel a request |
Returns
A Promise resolving to a Recommendations object:
{
// v2
[key: string]: {
items: RecommendProduct[];
title: string;
ruleEngine: string;
ruleset: string;
};
// v3
[key: string]: {
items: RecommendProduct[];
title: string;
};
}getResultsById
getResultsById
Description: Fetches recommendation results for a single elementId.
Parameters
Name | Type | Required | Description |
|
| ✅ (for v2) | The ID of the element that you want to fetch results for |
|
| ✅ (for v3) | The ID of the container that you want to fetch results for |
↳ |
| ❌ | The version of the API to use. v2 corresponds with the experience api, while v3 corresponds with the containers api. |
↳ |
| ❌ | The pathname that includes the locale (default to 'default' locale) |
↳ |
| ❌ | The query string of the page |
↳ |
| ❌ | The locale to get items from |
↳ |
| ❌ | Product codes to exclude from the recommendations separated by |
↳ |
| ❌ | Product codes of recently viewed items separated by |
↳ |
| ❌ | Product code of the currently viewed product on a PDP page. Used to enhance recommendations. |
↳ |
| ❌ | Product code of the target product (used for passing a product code for anything other than a PDP page) |
↳ |
| ❌ | Context object used for dynamic filtering |
|
| ❌ | An optional queryId passed to cancel a request |
Returns
A Promise resolving to a Recommendations object:
{
// v2
items: RecommendProduct[];
title: string;
ruleset: string;
ruleEngine: string;
// v3
items: RecommendProduct[];
title: string;
}