Basic Usage

Prev Next

Basic Usage focuses on how to use the SDK once it’s installed. Below, find example code for importing the client, creating an instance, and calling service methods like search or recommend.

More detailed API docs and copy-paste examples can be found in the API documentation for each service.

Please also reference our XSearch Service, XRecommend Service, Tracking Service section for more examples.

import XGenClient from '@xgenai/sdk-core';

const xg = new XGenClient({

  key: '<your_api_key>',

  secret: '<your_api_secret>',

  clientId: '<your_client_id>',

  trackerId: '<your_tracker_id>',

getEnv: () => 'stage', //optional: function that returns the environment (`stage` or `prod`)

  authStore: new LocalCookieAuthStore() //default - can pass in a custom auth store instance

});

// get recommendations by element id

const result = await xg.recommend.getResultsById({elementId: '<element_id>'})

// and much more...