Skip to content

API Library

The API Library, esales-lifestyle-api, is built on top of the HTTP API and it is designed to make it easy to communicate with eSales Lifestyle from a site. It provides methods to make HTTP requests available in the Web API as well as TypeScript models of the response objects.

The library additionally facilitates the generation and handling of session key, customer keys, and methods for notifications.

Installation

The esales-lifestyle-api package is available for installation via npm. For more information about installation, requirements, usage and more, see esales-lifestyle-api at npm.

API instantiation

To work with the esales-lifestyle-api, the webApiId received during the customer onboarding is required as well as the correct market id. Below, the API object is instantiated as a constant, api.

const api = esales({ market: 'UK', webApiId: 'w1A2B3C45' });

Key handling

The esales-lifestyle-api offers support for working with session keys and customer keys, which are needed when making various requests. Keys are generated and locally persisted upon request and can be set or reset, which should be used when visitors signs in or out. For more information about identifying visitors, see Visitor Identification.

All examples below have instantiated the API object as a constant, api.

api.session.sessionKey;

// => 'fb91cf58-a5d7-cca9-f30f-50f745ddd46b'
api.session.customerKey;

// => '77661ff6-fba3-4ce4-9da4-609323ea22d1'
api.session.customerKey = '822c7ed1-30a6-4ea2-9768-540ae06dbfe1'

// => '822c7ed1-30a6-4ea2-9768-540ae06dbfe1'
api.session.reset();
console.log(api.session.sessionKey, api.session.customerKey);
// => '85f6104e-6763-4b6e-92f9-a3063d2a3cc8', '85f6104e-6763-4b6e-92f9-a3063d2a3cc8'

The examples can be tested by using a web browser console on the eSales Lifestyle live demo.

Notifications

The API library provides methods for making notifications using sendBeacon as this avoids cancelled notification requests during navigations when page is unloaded. Once the API object have been instantiated, notifications can easily be made, as session- and customer keys are automatically applied.

All examples below have instantiated the API object as a constant, api.

// @param ticket is present on product and variant
api.notify.click("L2FkLWluZm9ybWF0aW9uO2FkX2tleTthZDEwcm9kdWN0X2tleTtQMjs")
// @param ticket is present on product and variant
api.notify.addToCart("L2FkLWluZm9ybWF0aW9uO2FkX2tleTthZDEwcm9kdWN0X2tleTtQMjs")
// @param productKey is present on product
api.notify.addFavorite("1001-100")
// @param productKey is present on product
api.notify.removeFavorite("1001-100")

Last update: December 11, 2020
×
Copyright

This online publication is intellectual property of Apptus Technologies. Its contents can be duplicated in part or whole, provided that a copyright label is visibly located on each copy and the copy is used in conjunction with the product described within this document.

All information found in these documents has been compiled with utmost attention to detail. However, this does not guarantee complete accuracy. Neither Apptus Technologies nor the authors shall be held liable for possible errors or the consequences thereof.

Software and hardware descriptions cited in these documents might be registered trademarks. All trade names are subject to copyright restrictions and may be registered trademarks. Apptus Technologies essentially adheres to the manufacturer’s spelling. Names of products and trademarks appearing in this document, with or without specific notation, are likewise subject to trademark and trade protection laws and may thus fall under copyright restrictions.

CLOSE