Gathering detailed insights and metrics for recombee-js-api-client
Gathering detailed insights and metrics for recombee-js-api-client
Gathering detailed insights and metrics for recombee-js-api-client
Gathering detailed insights and metrics for recombee-js-api-client
JavaScript client for easy use of the Recombee recommendation API from frontend
npm install recombee-js-api-client
Typescript
Module System
Node Version
NPM Version
JavaScript (99.53%)
HTML (0.47%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
23 Stars
19 Commits
11 Forks
3 Watchers
2 Branches
9 Contributors
Updated on May 07, 2025
Latest Version
5.0.2
Package Id
recombee-js-api-client@5.0.2
Unpacked Size
922.02 kB
Size
135.43 kB
File Count
32
NPM Version
10.9.0
Node Version
23.3.0
Published on
Mar 21, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A javascript library for easy use of the Recombee recommendation API.
It is intended for usage in browsers and other client side integrations (such as in React Native / NativeScript mobile apps). For Node.js SDK please see this repository.
Documentation of the API can be found at docs.recombee.com.
The library is UMD compatible.
You can download recombee-api-client.min.js and host it at your site, or use a CDN such as jsDelivr CDN:
1<script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@5.0.2/dist/recombee-api-client.min.js"></script>
and use the global recombee
object.
1npm install recombee-js-api-client 2# or 3yarn add recombee-js-api-client 4# or 5pnpm add recombee-js-api-client 6# or 7bun add recombee-js-api-client
and import into your code using
1import recombee from 'recombee-js-api-client' 2// or 3const recombee = require('recombee-js-api-client');
The library ships with types, so you should get autocomplete in your IDE out of the box. If you're using TypeScript, it should recognize these correctly and warn you about any type errors.
This library allows you to request recommendations and send interactions between users and items (views, bookmarks, purchases ...) to Recombee. It uses the public token for authentication.
It is intentionally not possible to change the item catalog (properties of items) with the public token, so you should use one of the following ways to send it to Recombee:
1// Initialize client with name of your database and PUBLIC token 2const client = new recombee.ApiClient('name-of-your-db', '...db-public-token...', {region: 'us-west'}); 3 4// Interactions take the ID of the user and the ID of the item 5client.send(new recombee.AddBookmark('user-13434', 'item-256')); 6client.send(new recombee.AddCartAddition('user-4395', 'item-129')); 7client.send(new recombee.AddDetailView('user-9318', 'item-108')); 8client.send(new recombee.AddPurchase('user-7499', 'item-750')); 9client.send(new recombee.AddRating('user-3967', 'item-365', 0.5)); 10client.send(new recombee.SetViewPortion('user-4289', 'item-487', 0.3));
You can recommend items to user, recommend items to item or even recommend Item Segments such as categories, genres or artists.
It is possible to use Promises or callbacks.
1// Get 5 recommendations related to 'item-365' viewed by 'user-13434' 2const response = await client.send( 3 new recombee.RecommendItemsToItem("item-356", "user-13434", 5) 4); 5// or 6client 7 .send(new recombee.RecommendItemsToItem("item-356", "user-13434", 5)) 8 .then(function (res) { 9 console.log(res.recomms); 10 }) 11 .catch(function (error) { 12 console.log(error); 13 // use fallback... 14 });
Callback function take two parameters:
null
if request succeeds or Error
object1const callback = function (err, res) { 2 if (err) { 3 console.log(err); 4 // use fallback ... 5 return; 6 } 7 console.log(res.recomms); 8}; 9 10// Get 5 recommendations for user-13434 11client.send(new recombee.RecommendItemsToUser("user-13434", 5), callback);
Personalized full-text search is requested in the same way as recommendations.
1const searchQuery = " ... search query from search field ...."; 2const response = await client.send( 3 new recombee.SearchItems("user-13434", searchQuery, 5) 4); 5// or 6client 7 .send(new recombee.SearchItems("user-13434", searchQuery, 5)) 8 .then(function (res) { 9 console.log(res.recomms); 10 }) 11 .catch(function (error) { 12 console.log(error); 13 // use fallback... 14 });
1const searchQuery = " ... search query from search field ...."; 2client.send(new recombee.SearchItems("user-13434", searchQuery, 5), callback);
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 the next page. See Recommend next items for more info.
1const initialRecomms = await client.send( 2 new recombee.RecommendItemsToUser("user-13434", 5) 3); 4// Get next 3 recommended items as user-13434 is scrolling the page down 5const nextRecomms = await client.send( 6 new recombee.RecommendNextItems(initialRecomms.recommId, 3) 7 // notice we're using recommId from previous request ^ 8);
Recommendation requests accept various optional parameters (see the docs). Following example shows some of them:
1client.send(new recombee.RecommendItemsToUser('user-13434', 5, 2 { 3 scenario: 'homepage', // Label particular usage. You can assign various settings 4 // for each scenario in the Admin UI (https://admin.recombee.com/). 5 returnProperties: true, // Return properties of the recommended items 6 includedProperties: ['title', 'img_url', 'url', 'price'], // Use these properties to show 7 // the recommended items to user 8 filter: "'title' != null AND 'availability' == \"in stock\"" 9 // Recommend only items with filled title 10 // which are in stock 11 } 12), callback); 13 14
You can use a script or set a product feed at Recombee web admin. We will set following sample Google Merchant product feed: product_feed_sample.xml. You will see the items in web interface after the feed is processed.
Let's assume we want to show recommendations at product page of pants product-270
to user with id user-1539
. The following HTML+js sample send the detail view of the product by the user and request 3 related items from Recombee:
1<!DOCTYPE html> 2<html lang="en"> 3<head> 4 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 5</head> 6<body> 7 <div class="container"> 8 <div class="row"> 9 <h1>Related products</h1> 10 <div class="col-md-12"> 11 <div class="row" id='relatedProducts'> 12 </div> 13 </div> 14 </div> 15 </div> 16 17 <script src="https://cdn.jsdelivr.net/gh/recombee/js-api-client@5.0.2/dist/recombee-api-client.min.js"></script> 18 19 <script type="text/javascript"> 20 21 // A simple function for rendering a box with recommended product 22 function showProduct(title, description, link, imageLink, price){ 23 return [ 24 '<div class="col-md-4 text-center col-sm-6 col-xs-6">', 25 ' <div class="thumbnail product-box" style="min-height:300px">', 26 ' <img src="' + imageLink +'" alt="" />', 27 ' <div class="caption">', 28 ' <h3><a href="' + link +'">' + title + '</a></h3>', 29 ' <p>Price : <strong>$ ' + price + '</strong> </p>', 30 ' <p>' + description+ '</p>', 31 ' <a href="' + link +'" class="btn btn-primary" role="button">See Details</a></p>', 32 ' </div>', 33 ' </div>', 34 '</div>' 35 ].join("\n") 36 } 37 38 // Initialize client 39 const client = new recombee.ApiClient('js-client-example', 'dXx2Jw4VkkYQP1XU4JwBAqGezs8BNzwhogGIRjDHJi39Yj3i0tWyIZ0IhKKw5Ln7', {region: 'eu-west'}); 40 41 const itemId = 'product-270'; 42 const userId = 'user-1539' 43 44 // Send detail view 45 client.send(new recombee.AddDetailView(userId, itemId)); 46 47 // Request recommended items 48 client.send(new recombee.RecommendItemsToItem(itemId, userId, 3, 49 { 50 returnProperties: true, 51 includedProperties: ['title', 'description', 'link', 'image_link', 'price'], 52 filter: "'title' != null AND 'availability' == \"in stock\"", 53 scenario: 'related_items' 54 }), 55 (err, resp) => { 56 if(err) { 57 console.log("Could not load recomms: ", err); 58 return; 59 } 60 // Show recommendations 61 const recomms_html = resp.recomms.map(r => r.values). 62 map(vals => showProduct(vals['title'], vals['description'], 63 vals['link'], vals['image_link'], vals['price'])); 64 document.getElementById("relatedProducts").innerHTML = recomms_html.join("\n"); 65 } 66 ); 67 </script> 68 69</body> 70</html>
You should see something like this:
Please notice how the properties returned by returnProperties
& includedProperties
were used to show titles, images, descriptions and URLs.
In order to achieve personalization, you need a unique identifier for each user. An easy way can be using Google Analytics for this purpose. The example then becomes:
1ga('create', 'UA-XXXXX-Y', 'auto'); // Create a tracker if you don't have one 2 // Replace the UA-XXXXX-Y with your UA code from Google Analytics. 3 4const client = new recombee.ApiClient('js-client-example', 'dXx2Jw4VkkYQP1XU4JwBAqGezs8BNzwhogGIRjDHJi39Yj3i0tWyIZ0IhKKw5Ln7'); 5 6ga(function(tracker) { 7 const userId = tracker.get('clientId'); // Get id from GA 8 9 client.send(new recombee.RecommendItemsToUser(userId, 3, 10 { 11 returnProperties: true, 12 includedProperties: ['title', 'description', 'link', 'image_link', 'price'], 13 filter: "'title' != null AND 'availability' == \"in stock\"", 14 scenario: 'homepage' 15 }), 16 (err, resp) => { ... } 17 ); 18}); 19
This time RecommendItemsToUser is used - it can be used for example at your homepage.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
1 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More