Build a web app for the Insight Advisor API
The tutorial Explore app content using the Insight Advisor APIs laid the groundwork for gaining analytic insights through the Insight Advisor API using Postman. This tutorial builds on your knowledge by showing you how to call the same API endpoints using a web app. It is recommended that you review the first tutorial before proceeding with this one. It would also be helpful to have a basic understanding of JavaScript programming and package managers.
In this tutorial, you will create a UI in a browser that allows you to pose natural language questions, or select dimensions and measures in conjunction with a specific analysis type. The result is an interactive chart based on your input. Here’s a preview of what the UI will look like.

This tutorial uses the following Insight Advisor API endpoints:
api/v1/apps/{appId}/insight-analyses
api/v1/apps/{appId}/insight-analyses/model
api/v1/apps/{appId}/insight-analyses/actions/recommend
Prerequisites
- Access to a Qlik Cloud tenant.
- “Demo App - Beginner’s tutorial” Qlik Sense application from this tutorial.
- Web integration ID configured to whitelist
http://localhost:1234
, unless you customize the code in the tutorial to use a different port or hostname. See Managing web integrations. - Visual Studio Code or similar code editor.
- Yarn package manager. (Yarn can be installed using node.js)
Supported charts
See charts for a list of chart types supported by Insight Advisor.
Quick start
If you want to dive right into the code, all of the code presented in this tutorial is available here.
1 Start the project
The first step is to create a root folder for the project called
insight-advisor-api-tutorial
. This folder will act as a container for your files.
2 Create an environment file
The idea here is to create a file that allows you to store environment variables in one place and isolate them from your app. This helps to keep the project organized.
-
In the root folder, create a file named
.env
to hold your tenant configuration details. -
Add the following code to the file:
PROJECT_NAME="Insight Advisor APIs"TENANT_URL="https://<TENANT_URL>"APP_ID="<APP_ID>"WEB_INTEGRATION_ID="<WEB_INT_ID>"Substitute the variables with the appropriate URL and IDs.
3 Create the package.json file
In the root folder, create a file named package.json
. This file will hold the
metadata relevant to the project such as the project’s dependencies, scripts,
and so on. Add the following code to your package.json
file:
{ "name": "insight-advisor-tutorial", "version": "0.0.1", "keywords": [ "qlik", "nebula" ], "scripts": { "start": "parcel src/index.html --open --no-hmr", "build": "parcel build src/index.html --dist-dir ./dist" }, "dependencies": { "@nebula.js/sn-bar-chart": "^1.x", "@nebula.js/sn-line-chart": "^1.21.11", "@nebula.js/sn-scatter-plot": "^3.42.0", "@nebula.js/stardust": "3.0.4", "dotenv": "^16.0.3", "enigma.js": "^2.6.3", "node-fetch": "2", "parcel": "^2.8.3", "prettier": "^2.8.3" }, "devDependencies": { "@babel/core": "^7.20.12", "buffer": "^5.7.1", "os-browserify": "^0.3.0", "path-browserify": "^1.0.1", "process": "^0.11.10" }}
4 Install the dependencies
In a terminal window, run the following commands from the root folder:
yarn install
yarn add @nebula.js/stardust
All the dependencies that are required by the app such as nebula.js, enigma.js, and other libraries and modules are installed in your project.
5 Define the user interface for the web app
Create a folder for your scripts, CSS, and HTML files within the root folder and
name it src
.
In the src
folder, create an index.html
file. This file will define all
the user interface (UI) elements that you need to display the app in your
browser. Add the following code to the file:
<!DOCTYPE html><html lang="en">
<head> <title>Insight Advisor APIs Demo</title> <meta charset="UTF-8" /> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <link rel="stylesheet" href="./style.css" /></head>
<body style="background-color: rgb(251, 251, 249);"> <div style="margin-left: 5%;"> <div class="form-check"> <input class="form-check-input" type="radio" name="flexRadioDefault" id="askQuestion" onchange="disableMetadataSelections()" checked> <label class="form-check-label" for="askQuestion"> Ask Question </label> </div> <div class="form-check"> <input class="form-check-input" type="radio" name="flexRadioDefault" id="selectMetadata" onchange="disableQuestionBox()"> <label class="form-check-label" for="selectMetadata"> Select Measure & Dimension </label> </div> </div> <form action="#" id="formId"> <div style="margin-left: 5%;"> <div class="form-group"> <input type="text" class="form-control" id="inputText" placeholder="Type Question Here" style="width: 53% !important; margin-top: 35px;"> </div> <div class="form-group"> <select class="form-control md-3" id="selectMeasure" style="width: 30% !important" disabled> <optgroup label="Fields" id="fieldMeasures"> <option>Select Measure</option> </optgroup> <optgroup label="Master Items" id="masterMeasures"> </optgroup> </select> </div> <div class="form-group"> <select class="form-control md-3" id="selectDimension" style="width: 30% !important" disabled> <optgroup label="Fields" id="fieldDimensions"> <option>Select Dimension</option> </optgroup> <optgroup label="Master Items" id="masterDimensions"> </optgroup> </select> </div> <div class="form-group"> <select class="form-control md-3" id="selectAnalysis" style="width: 30% !important" disabled> <option value="rank-rank">Select Analysis</option> </select> </div> </div> <div class="form-group"> <button type="submit" class="btn btn-success" id="btnSubmit" style="margin-left: 48%; width: 7%; font-size: 17px; background-color: #00873d;">Submit</button> </div> </form> <div id="app"> <div id="selection" class="curr-selections" style="width: 50% !important; margin-left: 5.2% !important;"></div> <div id="chart" style="width: 50% !important; margin-left: 4.5%"></div> </div> <script type="module" src="./index.js"></script> <script> function disableMetadataSelections() { document.getElementById("inputText").value = ''; document.getElementById("selectMeasure").disabled = true; document.getElementById("selectDimension").disabled = true; document.getElementById("selectAnalysis").disabled = true; document.getElementById("inputText").disabled = false; } function disableQuestionBox() { document.getElementById("inputText").value = ''; document.getElementById("inputText").disabled = true; document.getElementById("selectMeasure").disabled = false; document.getElementById("selectDimension").disabled = false; document.getElementById("selectAnalysis").disabled = false; } </script></body>
</html>