A selection of useful helpers for converting data into the required formats.


Converts a username and password string combination into a Basic Authorization token. toBasicAuth is a static method of the XAPI Class.

const username = "username";
const password = "password";
const auth = XAPI.toBasicAuth(username, password);
console.log(auth); // Basic dXNlcm5hbWU6cGFzc3dvcmQ=


Useful for calculating ISO8601 durations when submitting statements that require durations. calculateISO8601Duration is a static method of the XAPI Class.

const startDate: Date = new Date();
const endDate: Date = new Date(startDate);
endDate.setDate(endDate.getDate() + 1);
const duration = XAPI.calculateISO8601Duration(startDate, endDate));
console.log(duration); // P1DT


Gets the launch data if the module was launched using xAPI Launch. getXAPILaunchData is a static method of the XAPI Class.

XAPI.getXAPILaunchData().then((result) => {
const launchData: XAPILaunchData =;
this.xapi = new XAPI(launchData.endpoint); =;


Gets the launch data if the module was launched as a TinCan module. getTinCanLaunchData is a static method of the XAPI Class.

const tinCanLaunchData: TinCanLaunchParameters = XAPI.getTinCanLaunchData();
const xapi = new XAPI(tinCanLaunchData.endpoint, tinCanLaunchData.auth);
const actor =;


Converts search query parameters from a string into an object. getSearchQueryParamsAsObject is a static method of the XAPI Object. Used in getTinCanLaunchData and getXAPILaunchData. If any JSON is detected an attempt is made to parse it, else properties are returned as decoded strings.

// Location: index.html?
const queryParamsString =;
const queryParamsObject = XAPI.getSearchQueryParamsAsObject(queryParamsString);
// { endpoint: "" }

For backwards compatibility with some LMS, if an actor property is found containing string arrays for name, mbox and account these are converted into objects containing the first array entry only. Also if the property is account the first array object is converted from:

[{ accountServiceHomePage: "...", accountName: "..." }]


{ homePage: "...", name: "..." }