Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
This article explains how to send a simple ticket request to Qlik Sense Proxy API to get a ticket with node.js.
Environments:
In order to send the request, we will use Express (a Node.js webserver module) and the following code into two files ticket.js and index.js. This is hardcoded to a specific user, to show bare-bones how this works, you will need to modify this example to take inputs from the user.
/***** index.js *****/
const express = require('express');
const ticket = require('./ticket');
var app = express();
app.get('/index.html', function(req,res) {
console.log("accessed the index.html node page");
console.log("proxyRestUri: " + req.query.proxyRestUri);
console.log("targetId: " + req.query.targetId);
ticket.get_ticket_redirect(req.query.proxyRestUri, req.query.targetId, function(redirectUrl){
console.log("Redirecting to "+redirectUrl);
res.redirect(redirectUrl);
});
});
app.use('/', express.static('public'));
app.listen(3000, function() {
console.log("Listening on port 3000");
});
/***** ticket.js *****/
var fs = require('fs');
var request = require('request');
//define certificate folder
var directory = "C:\\ProgramData\\Qlik\\Sense\\Repository\\Exported Certificates\\your-sense-server\\";
var get_ticket_redirect = function(proxyRestUri, targetId, callback){
//set up request options
var options = {
uri: proxyRestUri + 'ticket?xrfkey=somerandomstring',
headers: {'content-type': 'application/json',
'X-Qlik-xrfkey': 'somerandomstring',
'X-Qlik-user': 'UserDirectory=SomeDomain;UserId=SomeUser'
},
method: 'POST',
body: {
"UserDirectory": "SomeDomain",
"UserId": "SomeUser",
"Attributes": [],
"TargetId": targetId
},
json: true,
ca: fs.readFileSync(directory+ "root.pem"),
key: fs.readFileSync(directory+"client_key.pem"),
cert: fs.readFileSync(directory+"client.pem"),
rejectUnauthorized: false
};
//send request
request(options, function (error, response, body) {
if(error)
{
console.log('Error: '+error);
console.log(response);
}
else
{
console.log("== Got a ticket ==");
console.log("Ticket: " + response.body.Ticket);
console.log("TargetUri: " + response.body.TargetUri);
callback(response.body.TargetUri + "?QlikTicket=" + response.body.Ticket); // This is the redirect URL!
}
});
}
module.exports = {
get_ticket_redirect: get_ticket_redirect
}
Next
Finally, in order to execute above codes, run the command line:
C:\requestTicket>node index.js
If successful, it should return something like
C:\Users\YourUser\YourNodeApp>node index.js
Listening on port 3000
Testing
if the user requested https://yourserver/external-module/hub ("external-module" being the virtual proxy prefix here), and the virtual proxy is configured to send the user to https://yourauthserver:3000/index.html
Virtual Proxy settings to redirect the request to the module:
In the command line, the following will appear:
accessed the index.html node page proxyRestUri: https://yourserver:4243/qps/external-module/ targetId: 0f0daaad-288c-4d72-ba3e-19b522df88c1 == Got a ticket == Ticket: rDw8esOwdMCjMhZK TargetUri: https://yourserver/external-module/hub/ Redirecting to https://yourserver/external-module/hub/?QlikTicket=rDw8esOwdMCjMhZK
Or an error if the request fails.
Note: Debugging or writing custom code is supported by the Qlik Professional Services or Presales teams. This example is provided for demonstration purposes to explain specific scenarios. No Support or maintenance is implied or provided. Further customization is expected to be necessary and it is the responsibility of the end administrator to test and implement an appropriate implementation for their specific use case.
Note: Qlik does NOT support the 3rd party software mentioned and used in this documentation. Please use them at your own discretion and, if concerned, contact the proper IT team within your company to verify the ability to use non-Qlik related software in the environment.
What is targetId??
and where to find it or get it.
e.g targetId: 0f0daaad-288c-4d72-ba3e-19b522df88c1 how it came in final output??
Hello @rammilan20
TargetID is a parameter saving the URL you were trying to access before being redirected to the authentication page. It maps the targetId and the actual URL in memory in the Qlik Proxy service.
If you require more detailed assistance with this topic, please post about what you are attempting to accomplish in our Qlik Sense Integrations and APIs forum.
All the best,
Sonja
There is a TargetUri that seems to be the URL you were trying to access before being redirected @Sonja_Bauernfeind
So it must be something different. Furthermore, targetID in the example is not an URL, it is a sort of hash: 0f0daaad-288c-4d72-ba3e-19b522df88c1
I didn't found any info regarding this targetID on the Internet. And the powershell example is not using any TargetID param
Could someone from Qlik plz clarify?
Hello @virilo_tejedor
I'll take this to our subject matter experts to see what additional information we can provide.
All the best,
Sonja
@rammilan20 @Sonja_Bauernfeind
Here you have the answer from @Damien_V
> Qlik Sense will remember what URL you tried to access before getting redirected to the authentication module and store it in memory as an ID, the mapping between the actual URL and the ID is stored in the Qlik Proxy service memory and cannot be seen directly.