If you use Qlik Sense, eventually you will need to automate the execution of the data loading tasks.
Qlik Sense implements a REST API to make this and much more things. It is called Qlik Sense Repository Service API or QRS API.
There are several ways to authenticate our calls to the server. Here we will use a server certificate instead of Windows or HTTP Header Authentication.
To export the server certificates, we need to access the QMC console with admin privileges. Once you are logged into the QMC, click in the last option on the left menu “Certificates”.
You will need to enter a machine name and also a password if you want to protect your certificate. Remember, if you don’t specify a password, anyone who has access to the certificate file will have the capabilities of an admin via the Qlik Sense API.
Change the file format of the certificate to .pem and note the location where the .zip file that contains the certificates will be saved.
If you go now to the folder mentioned above and everything went ok, you will find a zip file. Unzip the file and copy both files inside (client.pem & client_key.pem) into a safe folder or an usb pen that we will reference later.
Now, let’s go to our Linux station to create the utility script that we can use to start Qlik Sense tasks.
Of course, the Qlik Sense server has to be accessible from this station.
1.- Create a folder to store both the script and the certificate files
2.- Access the new folder and create a new one to store the certificate files
3.- Copy the cert files from your usb device or the folder where you stored them before. Once you’ve finished, there should be two files inside the cert folder you created in step 2.
4.- Now, let’s create the sh script:
4.1.- Inside /op/qliktasks folder open nano or vim to create the file taskStart.sh
4.2.- Make up a 16 characters long key that you will specify later in the query string and a header of the curl request. For instance:
4.3- Copy the following content inside the file updating the files path and the 16 long key. This is a very important step because the files need to be specified with an absolute path.
curl --key /opt/qliqtasks/cert/client_key.pem \
--cert /opt/qliqtasks/cert/client.pem \
-X POST \
--header "Content-type:application/json" \
--header "x-qlik-xrfkey: MySixteenLongKey" \
--header "X-Qlik-User: UserDirectory=internal;UserId=sa_repository" \
4.4.- Save the file (CTRL + O), confirm and exit (CTRL + X) the editor
4.5.- Activate execution flag
chmod +x startTask.sh
5.- Now we are ready to execute a Qlik Sense task by specifying its UUID.
How to find the task UUID?
Go to QMC tasks panel and find the column menu in the top right corner. Simply activate the ID checkbox and copy from the new column the UUID of the task you need to invoke.
7 thoughts on “How to invoke a Qlik Sense task from the command line”
I Hope this will work for Qliksense cloud,
I am new to this Qliksense, I have to create a job to trigger the Qliksense application from Unix. Is it possible firstly?. I have few basic questions,
1. How to access qliksense server from unix server.
2. How to get this key “Make up a 16 characters long key that you will specify later in the query string and a header of the curl request.” Is it a key created by us.
3. For the app created in Qliksense, do we get the UUID? By that UUID can we trigger Qliksense job from Unix.
I can’t answer if this will work on cloud or not. I guess the only issue you can face is not having the server certificate (but maybe there is a way to get it)
1.- The instructions given in the post are for a unix machine.
2.- Yes, it is created by you. It has to be 16 chars long
3.- The UUID you have to use is the UUID of a task, not an APP UUID. A Qliksense application cannot be invoked, but a task that executes the data loadings for an app can be.
I encourage you to take a look to https://www.pangodream.es/how-to-invoke-a-qlik-sense-task-from-node-js . It could help you as well.
Regards and thanks for commenting.
Do we need to open port 4242 between Qlik & Linux server? Also, do we need to add user in Qlik who is invoking script from Linux ?
If port 4242 (or the one the Qliksense server is listening at) is closed then yes, you need to open it.
No, you don’t need to add any user at all. A server certificate is used to authenticate the session.
Thank you so much! It’s helped me a lot!
Very nice and informative article, Could you be able to guide how we can do this on Qliksense Cloud.