JavaScript API
The Exago JavaScript (JS) API allows Exago functionality to be embedded directly into HTML <div>
containers.
<div>
s can inherit code and styles from the host application. Since CSS cascades down to Exago as well as up to the parent app, a single base of styles can be used, rather than separate ones for the host app and for Exago. The Exago DOM is accessible from the host application, so custom scripting is possible without being limited to Introduction to Action Events.
Background
The JS API implements asynchronous calls to Exago BI in the client browser. Besides the advantages of embedding in <div>
s and interacting programmatically, the API allows for multiple calls without needing to generate a new session for each one. As sessions are created once per page load, this can increase the feeling of responsiveness in the host application.
As the JS API runs on the client-side, it is not standalone. Session objects are still required to be generated, either with the .NET or REST Web Service API. Session objects must include any relevant user permissions and configuration settings.
A parameter called the ApiKey encodes the session object in a string, which is passed from the server-side API to the JS API. The JS API then initializes a JS API object, which is analogous to an Exago user session.
JS API objects are static and single-use. They cannot persist between page loads, and multiple JS API objects cannot be active on the same page.
The JS API object provides a set of functions that are used to implement elements of Exago BI functionality.
API Actions and active reports should not be set when using the JS API as doing so may produce errors within the API session. Any desired actions, such as executing a report or editing a report on the page, should be done using the appropriate Functions instead.
Setup and Configuration
These steps describe how to configure the environment to use the JS API, as well as how to implement it in an application.
1. Create the Session
- Use the .NET API or REST Web Service API to set up the session. Make all configuration changes there, as these settings cannot be changed once the JS API object is loaded.
.NET API
Instantiate an API object with one of the available constructors.
Example:API api = new API("appPath");
REST Web Service API
The
Id
is the session ID (sid) that will be needed for subsequent REST Web Service API calls. Save the value of the ApiKey property, as it will be needed to instantiate the JS API object in step 2.POST http://server/webservice_virtual_path/rest/sessions
with this payload:{
"AppUrl": "UrlParamString",
...
"Id": "1234-5678-9012-3456",
...
}
- Set the WebAppBaseUrl property to the virtual directory where Exago BI is installed:
.NET API
api.SetupData.WebAppBaseUrl = "http://server/Exago/";
REST Web Service API
Do either one of the following:
- PATCH
/Rest/Settings?sid={sid}
. This method requires the session be established first in step 1. Payload:{
"WebReportsBaseUrl" : "http://server/Exago"
}
- Add to the web service config file ({WebService}/Config/WebReportsApi.xml):
<webreportsbaseurl>http://server/Exago/</webreportsbaseurl>
In contrast to the .NET and REST Web Service APIs, the JavaScript API has no concept of an Active Report or an API Action. Instead, the action and report are specified by calling the individual Functions.
A side-effect of this is that per-session report changes cannot be made in memory, since the JS API function can only act on saved reports. Changes will need to be saved to storage before execution.
- PATCH
- Once the session is ready, get the ApiKey if not saved in step 1.1 (skip this step if you already have the ApiKey). This encodes the session settings to pass to the JS API. This API key will need to be passed to the page as it will be used in client side JavaScript calls.
.NET API
return api.GetApiKey();
REST Web Service API
GET
Rest/Sessions/{sid}
, then get the ApiKey property from the response object:{
...
"ApiKey": "encodedAlphanumericApiKey"
}
2. JS API Object
- Load the JS API library into the host web application via a
<script>
tag:<script src="http://server/Exago/WrScriptResource.axd?s=ExagoApi"></script>
WrScriptResource.axd
is not a file on the file system, it is a virtual file that contains the necessary scripts to load the API."http://server/Exago"
is the URL to the virtual path of the Exago BI Web Application. - Using the ApiKey, instantiate an ExagoApiJavaScript API object. There are two constructors available:
Constructor 1
var api = new ExagoApi(ExagoBaseURL, ApiKey, onLoadCallback, [showErrorDetail]);
- ExagoBaseURL — URL to the installation of Exago BI
- ApiKey — key generated when the session was created
- onLoadCallback — function to execute once the JS API has been fully loaded and is ready for use
- Optional: showErrorDetail — set to true to see more detailed application error messages. (Default: False).
Example
new ExagoApi("https://exago.example.com", "tCq0n6dMl6kQEbgofptKsdinMINJpqsClF5kVnzz2wcgcEfGjYE8eEeKjR3NBkjayZY%2fbs7RLTcpH9EtDyhRBA%3d%3d", () => { console.log("Exago is ready for further API calls!"); }, true);
Constructor 2 v2019.1.22+v2019.2.8+
This constructor contains an additional
OnError()
callback function. The definitions below are written using TypeScript syntax.var api = new ExagoApi(options: wrExagoApiOptions);
This constructor takes one argument, an object of type wrExagoApiOptions. wrExagoApiOptions objects are defined by the following interface:
interface wrExagoApiOptions { WebEndpoint: string; ApiKey: string; OnLoad: () => void; OnError?: (err: wrJsApiError) => void; OnDisposeContainer?: (container: HTMLElement) => void; ShowErrorDetail?: Boolean; IncludeCredentials?: Boolean; }
- WebEndPoint — URL to the installation of Exago BI
- ApiKey — key generated when the session was created
- OnLoad() — function to execute once the JS API has been fully loaded and is ready for use
- OnError() — optional: function to execute if the loading of the JS API fails. Takes one argument, an object of type wrJsApiError which simply represents an error message if loading of the API fails. A wrJsApiError object is defined by the following interface:
interface wrJsApiError {
Message: string;
}
- OnDisposeContainer — optional: function to execute when the
<div>
containing Exago is no longer needed and can be disposed. Takes one argument of type HTMLElement object, the ID of the containing<div>
. This is the recommended way of passing this function to the ExagoApi object. For more information, see Disposing Containers. - ShowErrorDetail — optional: true if full error messages should be displayed to the end user in the browser, false if they should be saved to the log only
- IncludeCredentialsv2019.2.29+v2020.1.13+v2021.1.1+ — optional: determines the credentials mode to use for any
XHR
orfetch
request.Request Type IncludeCredentials Value Result fetch omitted or true credentials
property of theRequest
object is set toinclude
fetch false credentials
property of theRequest
object is set tosame-origin
XHR true withCredentials
property of theXMLHttpRequest
object is set totrue
XHR false withCredentials
property of theXMLHttpRequest
object is set tofalse
OnError()
The
OnError()
callback function will be called under the following conditions:- Any HTTP 4xx or 5xx status code is returned from any XHR or fetch request involved with initialization
There are several use cases for the
OnError()
callback function, such as (but not limited to):- An expired ApiKey is passed
- An incorrect WebEndPoint is passed
- In a cross-origin environment, cookieless sessions are not enabled
- The Exago application server is down
Example
new ExagoApi({ WebEndpoint: "https://exago.example.com", ApiKey: "tCq0n6dMl6kQEbgofptKsdinMINJpqsClF5kVnzz2wcgcEfGjYE8eEeKjR3NBkjayZY%2fbs7RLTcpH9EtDyhRBA%3d%3d", ShowErrorDetail: true, OnLoad: () => { console.log("Exago is ready for further API calls!"); }, OnError: () => { console.log("There was an error loading Exago"); }, });
ApiKeys are single-use. Multiple instances are not supported nor necessary. Functions can be called against the object for the duration of the session.
Functions
The following functions are available for loading and managing Exago functionality.
Functions can only be used once the JS API is fully loaded. Wait for
onLoadCallback()
orOnLoad()
to indicate that the API is ready.
Due to a known issue, the callbacks mentioned in the following JavaScript API functions only work as described as of v2018.1.12+ or v2018.2+.
LoadFullUI(container)
Load the full web application user interface in to a <div>
container.
Argument | Description |
---|---|
container | <div> container to place the user interface into |
The Full UI being loaded will block almost all other actions, so while the Full UI is displayed on screen, the host application cannot perform any other Exago functions such as executing reports or creating new reports.
ExecuteReport(container, exportType, reportPath, [udfOrOptions], [updateCallback], [errorCallback])
ExecuteReport(container, exportType, reportID, [udfOrOptions], [updateCallback], [errorCallback], true)
v2020.1.23+v2021.1.11+
ExecuteReport(container, exportType, reportPath, [udfOrOptions], [updateCallback], [errorCallback], false)
v2020.1.23+v2021.1.11+
Execute a report to a specific output type in a defined container.
Argument | Description |
---|---|
container | Div container to place the executed report into |
exportType | html|pdf|pdfsnapshot (v2021.2+)|csv|excel|rtf |
reportPath | Relative path to report to execute Example: “MyFolderMyReport” |
reportId v2020.1.23+v2021.1.11+ | The content ID of the report from the Storage Management database. When using this option, the useReportId argument must be passed as true. |
udfpre-v2019.1 | Optional: Report UDF information for use with folder management |
udfOrOptionsv2019.1+ | Optional: Report UDF information for use within folder management or a Report Options object for modifying reports before execution
|
updateCallback (container, updateType) | Optional: Callback to execute when the execution status changes, called when the report execution is starting and again when it is ready to be viewed
The parameter ‘updateType’ will assume one of these string values:
|
errorCallback (container, errorMessage) => string | Optional: Callback to execute in the event an execution blocking error occurs
Return value: See errorCallback return value. |
useReportId v2020.1.23+v2021.1.11+ | When calling a report by its Storage Management content ID, set this value to true. When calling a report by its report path, set this value to false.
|
ExecuteStaticReport(exportType, reportPath, udfOrOptions , successCallback, [errorCallback])
Execute an Advanced Report, and return its output to the successCallback function. Report is not interactive.
This function is only compatible with Advanced Reports.
Argument | Description |
---|---|
exportType | html|pdf|csv|excel|rtf|json |
reportPath | Relative path to report to execute Example: “MyFolderMyReport” |
udf pre-v2019.1 | Report UDF information for use with folder management |
udfOrOptions v2019.1+ | Report UDF information for use within folder management or a Report Options object for modifying reports before execution
|
successCallback (executionData) | Callback to execute when execution request returns
|
errorCallback (errorMessage) | Optional: Callback to execute in the event an error occurs.
Return value: See errorCallback return value. |
const container = ... const exportType = ... const reportPath = ... api.ExecuteStaticReport(exportType, reportPath, null, (executionData) => { if (exportType == "excel" || exportType == "rtf" || exportType == "pdf") container.innerHTML = "<iframe src="' + api.GetBaseAddress() + executionData + '"></ iframe>"; else container.innerHTML = executionData; }, (errorMessage) => { container.innerHTML = errorMessage; });
ScheduleReportWizard(container, reportPath, [udf], [errorCallback], [successCallback])
Start the Schedule Report Wizard for the specified report.
The optional
successCallback
is available in v2021.1.14+.
Argument | Description |
---|---|
container | Div container to place the scheduled report wizard into |
reportPath | Relative path to report to schedule Example: “MyFolder/MyReport” |
udf | Optional: Report UDF information for use with folder management |
errorCallback (container, errorMessage) => string | Optional: Callback to execute in the event an error occurs, such as the scheduler being disabled
Return value: see errorCallback return value. |
ScheduleReportManager(container, [errorCallback], [successCallback])
Open the Schedule Manager.
The optional
successCallback
is available in v2021.1.14+.
Argument | Description |
---|---|
container | Div container to place the scheduled report manager into |
errorCallback (container, errorMessage) => string | Optional: Callback to execute in the event an error occurs, such as the scheduler being disabled
Return value: see errorCallback return value. |
LoadReportTree(successCallback, [errorCallback])
Load the report tree as JSON, returned to the successCallback method.
Argument | Description |
---|---|
successCallback (reportTree) | Callback to execute once the report tree has been loaded.
|
errorCallback (errorMessage) | Optional: Callback to execute in the event an error occurs
|
EditReport(container, reportPath, [udf], [errorCallback], [successCallback])
Load the report designer for a report.
The optional
successCallback
is available in v2021.1.14+.
Argument | Description |
---|---|
container | Div container to place the report designer into |
reportPath | Relative path to report to edit Example: “MyFolderMyReport” |
udf | Optional: Report UDF information for use with folder management |
errorCallback (container, errorMessage) => string | Optional: Callback to execute if the report fails to load
Return value: see errorCallback return value. |
NewReport(container, reportType, [successCallback])
Create a new report in the corresponding Report Designer. For pre-v2020.1, passing advanced to the reportType
argument will start the New Report Wizard.
Note
The optional
successCallback
is available in v2021.1.14+.
Argument | Description |
---|---|
container | Div container to place the report designer into |
reportType | advanced|express|Dashboard|chained|expressview |
DisposeContainerContent(container)
Disposes the contents of a container and resets the system state to be aware of what containers are open.
Argument | Description |
---|---|
container | Div container to dispose |
Disposepage()
Disposes the contents of a page, removing any event listeners added to the page and performing other cleanup necessary for complete removal of the ExagoAPI instance. After calling DisposePage(), the ExagoAPI instance should be considered “closed.” Any new Exago JavaScript API calls must be performed on a new ExagoAPI instance.
IsAllowedReportType(reportType)
Returns whether or not a specified report type is allowed for the session.
Argument | Description |
---|---|
reportType | advanced|express|Dashboard|chained|expressview |
GetAllowedReportTypes()
Returns an array of the report types allowed for this session.
Example:
function RunReportJS() { var container = document.getElementById("ExagoDiv"); api.ExecuteReport(container, "html", "ExamplesClientReport"); }
Container
div
s must be empty or disposed before loading. Additionally, you should specify size and position constraints for eachdiv
.
div#ExagoDiv {
width: 1200px;
height: 600px;
position: relative;
}
Disposing Containers
It is important to properly dispose of containers when they are finished being used by explicitly calling the DisposeContainerContent(container) method.
Optionally, an OnDisposeContainer callback can be defined that will execute when a container has been disposed either implicitly or explicitly. This allows the host application to safely reset the container to whatever state necessary, or remove the container from the page entirely. When a user encounters an error that prevents the requested action, for example, ExecuteReport(…), the container will auto-dispose and execute the OnDisposeContainer callback if one is defined.
Example
api.OnDisposeContainer = function(container) { container.parentElement.removeChild(container); };
Disposing Pages v2018.2+
Once an ExagoAPI instance has been instantiated, DisposePage() must be called before instantiating subsequent ExagoAPI instances. DisposePage() will dispose the contents of an entire page, thereby disposing each instantiated container. Furthermore, it will remove any event listeners added to the page by the ExagoApi instance and perform other cleanup necessary for complete removal of the ExagoAPI instance.
After calling DisposePage(), the ExagoAPI instance should be considered “closed.” Any new Exago JavaScript API calls must be performed on a new ExagoAPI instance.
errorCallback return value
Whenever an error occurs that prevents the JS API action from updating a container (such as an undefined report name in a call of ExecuteReport), the following will happen:
- If errorCallback is not defined, an alert dialog will appear with the error message (or a placeholder error message, if the URL parameter ‘showerrordetail’ is set to false).
- If errorCallback is defined, it will first be called. If errorCallback returns a string (either the original error message or a custom message), an alert dialog will appear with the given string, or a placeholder error message if the URL parameter ‘showerrordetail’ is set to false.
- If errorCallback does not return a string, or the string is empty, no alert dialog will be shown and the DisposeContainerContent() method will run immediately.
Clicking on the error dialog’s dismiss button will close the dialog and call DisposeContainerContent(). The container’s content will be closed, the inner HTML will be cleared, and the OnDisposeContainer callback will be called.
Interfaces v2019.1+
The following interfaces are available for managing and modifying report settings at runtime.
wrJsApiExecuteReportOptions
Allows information for the modification of filters and parameters of a report to be passed to the udfOrOptions parameter of ExecuteReport(container, exportType, reportPath, [udfOrOptions], [updateCallback], [errorCallback]) functions. If this interface is passed to ExecuteReport the updateCallback and errorCallback parameters of this function will be ignored; however, they may be specified within this interface if necessary
All properties in the
wrJsApiExecuteReportOptions
object are optional.
Property | Description |
---|---|
Udf | The UDF information used to load the report if required |
UpdateCallback (container, updateType) => void | Callback to execute when there has been an update in the status of the report execution |
ErrorCallback (container, errorMessage) => string | Callback to execute in the event an error occurs |
NewFilters | An array of wrJsApiExecuteReportFilter objects defining the new filters to add to the report before execution begins |
PromptingFilterValues | An array of prompting filter values to modify before execution begins
|
Parameters | A list of wrJsApiExecuteReportParameter objects defining the non-hidden parameters to add or modify before execution begins |
wrJsApiExecuteStaticReportOptions
Allows information for the modification of filters and parameters of a non-interactive report to be passed to the udfOrOptions parameter of the ExecuteStaticReport function. If this interface is passed to ExecuteStaticReport the successCallback and errorCallback parameters of this function will be ignored; however, they may be specified within this interface if necessary.
All parameters in the
wrJsApiExecuteStaticReportOptions
object are optional.
Parameter | Description |
---|---|
Udf | The UDF information used to load the report if required |
SuccessCallback (execution) => void | Callback to execute when the report execution succeeds |
ErrorCallback (errorMessage) => string | Callback to execute in the event an error occurs |
NewFilters | An array of wrJsApiExecuteReportFilter objects defining the new filters to add to the report before execution begins |
PromptingFilterValues | An array of prompting filter values to modify before execution begins
|
Parameters | A list of wrJsApiExecuteReportParameter objects defining the non-hidden parameters to modify before execution begins. |
wrJsApiExecuteReportFilter
Defines the necessary information for a new filter. To be passed to wrJsApiExecuteReportOptions in order to add new filters to a report prior to execution.
wrJsApiPromptingFilterValue
Defines the necessary information to pass a value to a prompting filter for Advanced Reports. To be passed to wrJsApiExecuteReportOptions in order to set prompting filter values of a report prior to execution.
Property | Description |
---|---|
FilterText | The filter text used to identify which filter to modify |
Index | Optional: In the case of multiple filters having the same FilterText, the index into the matching group of filters
|
Operator | Optional: Reassign the condition used to match the data values to the specified filter value or values type wrJsApiFilterOperator =
|
Values | The values to add to the filter. Can be a string, number, or date, or an array of any of these types if multiple values are required (for example, for “Between” and “OneOf” filters).
|
wrJsApiCompositePromptingFilterValue
Defines the necessary information to pass a value to a prompting filter for Dashboards and Chained Reports, also known as “composite reports”. To be passed to wrJsApiExecuteReportOptions in order to set prompting filter values of a report prior to execution.
wrJsApiExecuteReportParameter
Defines the necessary information to add or modify non-hidden parameters. To be passed to wrJsApiExecuteReportOptions in order to add or set parameter values of a report prior to execution.
With multi-value parameters introduced in v2021.2.2, the Value property supports an array of values for those parameters that are already multi-value. Use the REST Web Service API or .NET API to change a Parameter between single or multi-value.
Property | Description |
---|---|
Name | The name of the non-hidden parameter to modify, without the ‘@’ symbols. |
Value | The value, or array of values to give to the parameter. Can be a string, number, or date depending on the parameter’s data type.
|
PromptText | The text that will display when prompting the user for a value. If this field is set to a null value, the parameter will be considered non-prompting. |