Overview
Pyramid Analytics is a Robust Analytics and Business Intelligence Platform which is used to process data from multiple sources and also create rich interactive reports and dashboards to gain insights.
Pyramid provides a wide array of features in its User Interface for enterprise users to help easily embed these dashboards in other web applications too. This can be achieved programmatically using the Pyramid JavaScript API as well.
These JavaScript API can also be used to retrieve only the relevant data from the reports and dashboards in a specified format, like CSV (comma-separated values), JSON (JavaScript Object Notation), and XML (extensible markup language), to formatted and display or used in external applications.
Continuing our series of posts to explore and understand the power of Pyramid Analytics, in this post, we are going to show how the Javascript API can be used to retrieve data in the required format by passing relevant parameters so that this information can be used in external web applications to create customized visualizations while the Data can be retrieved in real-time from Pyramid acting as a single version of the truth.
Enclosed is a sample of such custom web application visualization created by retrieving data from Pyramid.
Authentication with Pyramid and Retrieval of Token
The first step in using JavaScript API calls is to authenticate with the Pyramid server using the respective user credentials and retrieve a token to be used in subsequent API calls:
- API to Authenticate and Retrieve Token: “auth/authenticateUser”
Fig;1.1 Following Code section illustrates the process of retrieval of authenticated token from the Pyramid server via JavaScript API
// NOTE: callApi method is a generic. REST method is shown below.let token = callApi(“auth/authenticateUser”,{ “data”:{ “userName”:”admin”, “password”:”password” }},false); |
Accessing or retrieval of the query result data
Once we are done with the retrieval of the token from the Pyramid server, we can use this token in our webpage to get access to the required data either from a Discovery/Publication/Presentation stored in the Pyramid Server.
Given below is the API that will be required to get access to the query result data from Discovery. This will be done by passing the respective options along with the authentication token.
- API: “query/extractQueryResult”
- Report ID: Id of the discovery.
- ExportType: the export type in which you wish to see the data (JSON/CSV/XML).
Given below is FIg: 1.2 (code), which illustrates the access of the data in a specified JSON format by using the authenticated token from the Pyramid server with the help of javascript API.
// NOTE: callApi method is generic. REST method is shown below.let queryResult = callApi(“query/extractQueryResult “,{ “data”: { “itemId”:reportId, “exportType”:0, //JSON }, “auth”: token}); |
Fig: 1.2 (code)
Parameterization/filtering of the query result data
There is also a way for us to Filter and retrieve only required data from Discovery, Publication or Presentation in the Pyramid Server by passing relevant parameters to the API.
The API options that we require for the filtering of the retrieval data during JavaScript API calls on our web page is:
Option : externalParameters -> reportFilters
Fig: 1.3(Code) shown below illustrates the accessing of the data in a JSON format by using the authenticated token from the Pyramid server by using JavaScript API with Filtered/Parameterized data.
// NOTE: callApi method is generic. REST method is shown below.let queryResult = callApi(“query/extractQueryResult “,{ “data”: { “itemId”:reportId, “exportType”:0, //JSON “exportOptions”: {}, “externalParameters”: { “reportFilters”: [{ “value”: “[customers].[Country].[Filters].&[United States]” }, { “value”: “[customers].[State].[Filters].&[Alabama]” }] } }, “auth”: token}); |
Fig: 1.3 (code)
Fig: 1.4(Code) illustrates the JavaScript generic REST API calling the principal method which will be used to process the JavaScript API Call and to process the request of the API by reading its respective data options and would then provide a resultant data in JSON format.
// NOTE: callApi method is a generic REST method Calling method shown below will be called for respective API calls..function callApi(path,data,parseResult=true){console.log(‘path = ‘,path);console.log(‘data = ‘,data);console.log(‘parseResult = ‘,parseResult); var xhttp = new XMLHttpRequest(); xhttp.open(“POST”, pyramidURL+path, false); xhttp.send(JSON.stringify(data)); console.log(‘Called – xhttp.responseText = ‘,xhttp.responseText); if(parseResult){ return JSON.parse(xhttp.responseText); }else{ return xhttp.responseText; }} |
Fig: 1.4 (code)
Hope you enjoyed this article on Pyramid, stay tuned for more tips and tricks in coming articles. Please contact us to help with your implementations of Pyramid, we can help extend and customize Pyramid as per your requirements.