Class: CognosApi

CognosApi()

CognosApi is a client API framework class that builds a robust API for developing applications using CognosAnalytics components as a service.

Constructor

new CognosApi()

Constructor of the API client framework
Parameters:
Name Type Description
options.cognosRootURL string CognosAnalytics root URL
options.node object DOM node that will become the container of the client
options.sessionCode string sessionCode of the obtained session
options.initTimeout number (optional) initialization timeout (ms). Default 30000 ms.
options.language string (optional) Supported language. One of Object.keys(CognosApi.SUPPORTED_LANGUAGES). Default 'en'
Example
const cognosApi = new CognosApi({
	cognosRootURL: 'http://localhost/bi/',
	node: document.getElementById('containerDivId'),
	sessionCode: 'CD1a2b34567b8c901234d5',
	language: 'en'
});

Members

(static, readonly) EVENTS :string

Constant for event names used for on and off
Type:
  • string
Properties:
Name Type Description
REQUEST_ERROR string Request error events.
Allows users to receive HTTP request error events.

(static) SUPPORTED_LANGUAGES

List of supported languages.

Methods

initialize() → {Promise}

Initializes the CognosApi client.
Returns:
Promise that gets resolved with a Api instance is constructed with available APIs
Type
Promise
Example
const cognosApi = new CognosApi({
	cognosRootURL: 'http://localhost/bi/',
	node: document.getElementById('containerDivId'),
	sessionCode: 'CD1a2b34567b8c901234d5',
	initTimeout: 5000,
	language: 'en'
});
cognosApi.initialize().then(() => {
	console.log(cognosApi.dashboard);
}, (error) => {
	// Initialization took more than 5 seconds
	console.log(error);
});

updateModuleDefinitions(dashboardSpec, callback) → {Promise}

Allows the caller to update the module definitions inside the dashboard specification
Parameters:
Name Type Description
dashboardSpec String The dashboard specification
callback function A callback method which will be called with an array of module IDs. This callback should return an array of objects containing the module ID (id) and the new module definition (module).
Returns:
Promise that gets resolved with the updated dashboard specification
Type
Promise
Example
const cognosApi = new CognosApi({
	cognosRootURL: 'http://localhost/bi/',
	node: document.getElementById('containerDivId'),
	sessionCode: 'CD1a2b34567b8c901234d5',
	language: 'en'
});

cognosApi.initialize().then(() => {
	console.log(cognosApi.dashboard);
});

cognosApi.updateModuleDefinitions(oldDashboardSpec, (moduleIds) => {
	// Implement the callback that returns an array of the new module definitions.
	// The array of module definitions corresponds to the array of moduleIds
	return Promise.resolve(newModules);
}).then((newDashboardSpec) => {
	console.log(newDashboardSpec);
});