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. The example should be executed from a Node.js installation for which the steps are not covered here.

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.

var https = require('https'); var fs = require('fs'); var options = { hostname: 'rd-flp2.qliktech.com', 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 information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?