{"library":"recombee-js-api-client","title":"Recombee JavaScript API Client","description":"The `recombee-js-api-client` is a client-side JavaScript SDK designed for seamless integration with the Recombee recommendation API. Currently at version 6.2.1, it provides a thin wrapper around the Recombee API, enabling applications to send user-item interactions (such as detail views, purchases, or cart additions) and request personalized recommendations or search results. The library exhibits an active release cadence, with multiple minor and major versions released recently, indicating ongoing development and improvements. Key differentiators include its UMD compatibility, built-in TypeScript definitions, and its specific design for browser-based or other client-side environments like React Native or NativeScript. It is crucial to note that this client-side SDK focuses on data collection and recommendation retrieval using a public token and does not support catalog management operations for security reasons, which are handled by a separate server-side Node.js SDK.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install recombee-js-api-client"],"cli":null},"imports":["import recombee from 'recombee-js-api-client';","import recombee from 'recombee-js-api-client'; const client = new recombee.ApiClient(...);","import recombee from 'recombee-js-api-client'; const request = new recombee.AddDetailView(...);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import recombee from 'recombee-js-api-client';\n\nconst RECOMBEE_DATABASE_ID = process.env.RECOMBEE_DATABASE_ID ?? 'your-database-id';\nconst RECOMBEE_PUBLIC_TOKEN = process.env.RECOMBEE_PUBLIC_TOKEN ?? 'your-db-public-token';\nconst RECOMBEE_REGION = process.env.RECOMBEE_REGION ?? 'eu-west'; // e.g., 'us-west', 'eu-west'\n\n// Initialize the API client with your database ID and PUBLIC token\nexport const client = new recombee.ApiClient(\n  RECOMBEE_DATABASE_ID,\n  RECOMBEE_PUBLIC_TOKEN,\n  {\n    region: RECOMBEE_REGION,\n    // Optional: Increase default timeout if needed, e.g., 10 seconds\n    // timeout: 10000,\n  },\n);\n\n// Send interactions (e.g., AddDetailView, AddCartAddition, AddPurchase)\nclient.send(\n  new recombee.AddDetailView('user-4395', 'item-129', {\n    cascadeCreate: true, // Creates user/item if they don't exist\n    recommId: '23eaa09b-0e24-4487-ba9c-8e255feb01bb', // Optional: Link to a previous recommendation\n  }),\n).then(() => {\n  console.log('Detail view interaction sent successfully.');\n}).catch((error) => {\n  console.error('Failed to send detail view interaction:', error);\n});\n\n// Request recommendations (e.g., RecommendItemsToItem, RecommendItemsToUser)\nasync function getRecommendations() {\n  try {\n    const response = await client.send(\n      new recombee.RecommendItemsToItem('item-356', 'user-13434', 5, {\n        returnProperties: true, // Include item properties in the response\n        includedProperties: ['title', 'imageUrl'], // Specify which properties to return\n      }),\n    );\n\n    console.log('Recommendation ID:', response.recommId);\n\n    // The `recomms` array contains recommended items with their IDs and properties\n    response.recomms.forEach((item) => {\n      console.log(`Recommended Item ID: ${item.id}, Title: ${item.values?.title}, Image: ${item.values?.imageUrl}`);\n    });\n  } catch (error) {\n    console.error('Error requesting recommendations:', error);\n    // Implement fallback logic here, e.g., show popular items\n  }\n}\n\ngetRecommendations();","lang":"typescript","description":"Demonstrates initializing the Recombee client, sending a user-item interaction (a detail view), and requesting item-to-item recommendations with specified properties, including basic error handling.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}