Skip to content

Commit 05a8d70

Browse files
committed
Support RecommendNextItems endpoint
1 parent 0ed1c24 commit 05a8d70

13 files changed

+200
-34
lines changed

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The library is [UMD](https://github.com/umdjs/umd) compatible.
1515
You can download [recombee-api-client.min.js](./dist/recombee-api-client.min.js) and host it at your site, or use a CDN such as [jsDelivr](https://www.jsdelivr.com/) CDN:
1616

1717
```js
18-
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@3.0.1/dist/recombee-api-client.min.js"></script>
18+
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@3.1.0/dist/recombee-api-client.min.js"></script>
1919
```
2020

2121
### npm
@@ -86,7 +86,7 @@ client.send(new recombee.RecommendItemsToUser('user-13434', 5), callback);
8686
#### Promise
8787

8888
```javascript
89-
// Get 5 recommendations related to 'item-365' viewed by 'user-13434'
89+
// Get 5 recommendations related to 'item-365' viewed by 'user-13434'
9090
client.send(new recombee.RecommendItemsToItem('item-356', 'user-13434', 5))
9191
.then(function(res) {
9292
console.log(res.recomms);
@@ -122,19 +122,38 @@ client.send(new recombee.SearchItems('user-13434', searchQuery, 5))
122122
});
123123
```
124124

125-
#### Optional parameters
125+
### Recommend Next Items
126+
127+
Recombee can return items that shall be shown to a user as next recommendations when the user e.g. scrolls the page down (infinite scroll) or goes to a next page. See [Recommend next items](https://docs.recombee.com/api.html#recommend-next-items) for more info.
128+
129+
130+
```javascript
131+
client.send(new recombee.RecommendItemsToUser('user-13434', 5))
132+
.then(function(res) {
133+
console.log(res.recomms);
134+
135+
// Get next 3 recommended items as user-13434 is scrolling the page down
136+
client.send(new recombee.RecommendNextItems(res.recommId, 3))
137+
.then(function(res) {
138+
console.log(res.recomms);
139+
})
140+
});
141+
```
142+
143+
### Optional parameters
126144
Recommendation requests accept various optional parameters (see [the docs](https://docs.recombee.com/api.html#recommendations)). Following example shows some of them:
127145

128146
```javascript
129147
client.send(new recombee.RecommendItemsToUser('user-13434', 5,
130148
{
149+
scenario: 'homepage', // Label particular usage. You can assign various settings
150+
// for each scenario in the Admin UI (https://admin.recombee.com/).
131151
returnProperties: true, // Return properties of the recommended items
132152
includedProperties: ['title', 'img_url', 'url', 'price'], // Use these properties to show
133153
// the recommended items to user
134-
filter: "'title' != null AND 'availability' == \"in stock\"",
154+
filter: "'title' != null AND 'availability' == \"in stock\""
135155
// Recommend only items with filled title
136156
// which are in stock
137-
scenario: 'homepage' // Label particular usage
138157
}
139158
), callback);
140159

@@ -170,7 +189,7 @@ Let's assume we want to show recommendations at product page of pants `product-2
170189
</div>
171190
</div>
172191

173-
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@3.0.1/dist/recombee-api-client.min.js"></script>
192+
<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@3.1.0/dist/recombee-api-client.min.js"></script>
174193

175194
<script type="text/javascript">
176195

dist/recombee-api-client.js

Lines changed: 83 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/recombee-api-client.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/recombee-api-client.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/recombee-api-client.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "recombee-js-api-client",
3-
"version": "3.0.1",
3+
"version": "3.1.0",
44
"description": "Client-side js library for easy use of the Recombee recommendation API",
55
"browser": "./src/index.js",
66
"repository": {

src/errors/response-error.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const ae = require("./api-error");
77
class ResponseError extends ae.ApiError {
88
/**
99
* Create the exception
10-
* @param {Request} request - ID of the item which will be modified
11-
* @param {number} statusCode - The values for the individual properties
10+
* @param {Request} request - Request which caused the exception
11+
* @param {number} statusCode - The returned status code
1212
* @param {string} message - Error message from the API
1313
*/
1414
constructor(request, statusCode, message) {

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ exports.AddBookmark = require("./requests/add-bookmark").AddBookmark;
1616
exports.SetViewPortion = require("./requests/set-view-portion").SetViewPortion;
1717
exports.RecommendItemsToUser = require("./requests/recommend-items-to-user").RecommendItemsToUser;
1818
exports.RecommendItemsToItem = require("./requests/recommend-items-to-item").RecommendItemsToItem;
19+
exports.RecommendNextItems = require("./requests/recommend-next-items").RecommendNextItems;
1920
exports.SearchItems = require("./requests/search-items").SearchItems;

src/requests/recommend-items-to-item.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ const rqs = require("./request");
77

88
/**
99
* Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
10-
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1110
* The returned items are sorted by relevance (first item being the most relevant).
11+
* Besides the recommended items, also a unique `recommId` is returned in the response. It can be used to:
12+
* - Let Recombee know that this recommendation was successful (e.g. user clicked one of the recommended items). See [Reported metrics](https://docs.recombee.com/admin_ui.html#reported-metrics).
13+
* - Get subsequent recommended items when the user scrolls down (*infinite scroll*) or goes to the next page. See [Recommend Next Items](https://docs.recombee.com/api.html#recommend-next-items).
14+
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1215
*/
1316
class RecommendItemsToItem extends rqs.Request {
1417

@@ -66,7 +69,8 @@ class RecommendItemsToItem extends rqs.Request {
6669
* "url": "myshop.com/mixer-42"
6770
* }
6871
* }
69-
* ]
72+
* ],
73+
* "numberNextRecommsCalls": 0
7074
* }
7175
* ```
7276
* - *includedProperties*
@@ -92,7 +96,8 @@ class RecommendItemsToItem extends rqs.Request {
9296
* "price": 39
9397
* }
9498
* }
95-
* ]
99+
* ],
100+
* "numberNextRecommsCalls": 0
96101
* }
97102
* ```
98103
* - *filter*

src/requests/recommend-items-to-user.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ const rqs = require("./request");
88
/**
99
* Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
1010
* The most typical use cases are recommendations at homepage, in some "Picked just for you" section or in email.
11-
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1211
* The returned items are sorted by relevance (first item being the most relevant).
12+
* Besides the recommended items, also a unique `recommId` is returned in the response. It can be used to:
13+
* - Let Recombee know that this recommendation was successful (e.g. user clicked one of the recommended items). See [Reported metrics](https://docs.recombee.com/admin_ui.html#reported-metrics).
14+
* - Get subsequent recommended items when the user scrolls down (*infinite scroll*) or goes to the next page. See [Recommend Next Items](https://docs.recombee.com/api.html#recommend-next-items).
15+
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1316
*/
1417
class RecommendItemsToUser extends rqs.Request {
1518

@@ -54,7 +57,8 @@ class RecommendItemsToUser extends rqs.Request {
5457
* "url": "myshop.com/mixer-42"
5558
* }
5659
* }
57-
* ]
60+
* ],
61+
* "numberNextRecommsCalls": 0
5862
* }
5963
* ```
6064
* - *includedProperties*
@@ -80,7 +84,8 @@ class RecommendItemsToUser extends rqs.Request {
8084
* "price": 39
8185
* }
8286
* }
83-
* ]
87+
* ],
88+
* "numberNextRecommsCalls": 0
8489
* }
8590
* ```
8691
* - *filter*

0 commit comments

Comments
 (0)