Skip to main content

Connecting with Node.js

Node.js is a web technology that is based on the Google Chrome JavaScript engine. It has native functions for connecting to web services.

The following example shows how to use Node.js to connect to the Qlik Sense Repository Service (QRS) API and retrieve a list of apps in JSON format.

In the example, certificates are used for authentication and they must be in PEM format. The certificates can be obtained by exporting them from the Qlik Management Console (QMC) in PEM format including the secret key.

When using a certificate to authenticate, requests are made with full administrator rights. To run the commands as a specific user, add the X-Qlik-User header to use the security context of that user account.

To run this example:

  1. Copy and paste the following code into a text editor.
  2. Update the host name and certificate paths according to your environment.
  3. Save the file as get_apps.js.
  4. Execute the code from a Node.js installation:

    node get_apps.js

var https = require('https'); var fs = require('fs'); var options = { hostname: '', port: 4242, path: '/qrs/app?xrfkey=abcdefghijklmnop', method: 'GET', headers: { 'x-qlik-xrfkey' : 'abcdefghijklmnop', 'X-Qlik-User' : 'UserDirectory= Internal; UserId= sa_repository ' }, key: fs.readFileSync("C:\\client_key.pem"), cert: fs.readFileSync("C:\\client.pem"), ca: fs.readFileSync("C:\\root.pem") }; https.get(options, function(res) { console.log("Got response: " + res.statusCode); res.on("data", function(chunk) { console.log("BODY: " + chunk); }); }).on('error', function(e) { console.log("Got error: " + e.message); });

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!