Search code examples
javascriptpythondata-analysisqlikviewqliksense

How can I make a script in python to reload an app in qlik cloud


At this moment I'm trying to reload a Qlik app through a python script, but I had a few problems, I'm gonna explain the things I already tested, but if someone knows how can I solve that, I will appreciate it a lot

  • The first thing I tried, was the "reloads API" from qlik, to do this you have to send a request with the app id, and with the parameter "Partial" true or false, but even more important, you have to send with this request a JSON web token, so I was searching how to obtain the jwt of qlik and I found this page: "https://qlik.dev/tutorials/create-signed-tokens-for-jwt-authorization", I created all as the page said, and finally I make this code in javascript to test, but this doesn't work:

const fs = require('fs');
const uid = require('uid-safe');
const jwt = require('jsonwebtoken');
const https = require('https')

const payload = {
  jti: uid.sync(32), // 32 bytes random string
  sub: '(id of my user that appears in assignment users)',
  subType: 'user',
  name: '(Name of my user)',
  email: '(email of my user)',
  email_verified: true,
};

const privateKey = fs.readFileSync("path/certificate.pem");

// I don't know the meaning of that 'kid and issuer have to match with the IDP config' 
// audience has to be qlik.API/jwt-login-session
const signingOptions = {
  keyid: I put = 'my-custom-jwt',
  algorithm: I put = 'RS256',
  issuer: '(hostname)',
  audience: I put = 'qlik.api/login/jwt-session',
};

const myToken = jwt.sign(payload, privateKey, signingOptions);

const qlikUrl = "(hostname)"

const data = JSON.stringify({"appId": "(appId)", "partial": true})
const options = {
  hostname: qlikUrl,
  port: 443,
  path: '/api/v1/reloads',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer '+ myToken
  }
}

https.request(options)
req.write(data)

  • The second thing I did was, try to use the "qsAPI" library of python to connect to my qlik and reload an app specifying their id by a method of this library, but I don't understand what I have to put here, and in the documentation, doesn't say nothing about what's the meaning of the parameters, except ('hostname'). The problem is in the method to do the connection because I have to do this:

qrs = qsAPI.QRS(proxy='hostname', user=('yor_domain', 'username', 'password'))

I say that because if I go to the python IDE, this show which parameters I have to put, and these are different, now I have to put this:

qrs = qsAPI.QRS(proxy='hostname', user=('userDirectory', 'userId', 'password'))

  • I don't know where I can find the user directory because I don't know what it is.

  • The user id (I'm guessing it's the user id that appears in "mapping
    users").

  • The "password", is no problem

But still have an opportunity, because I can connect to Qlik through python if I find where I can download the certificate authentication of a user, but I don't know where is it in qlik cloud.

Can someone help me, please


Solution

  • I finally have the solution of that as Stefan Stoichev said before publishing this post, the qsApi seems to be a python library for Qlik Sense Enterprise on Windows, and the correct library for the Qlik Cloud is qsaas, but I'm going to explain every step because I don't want that any person of this world suffer this.

    First of all, you have to create an API KEY, in Qlik Cloud, IMPORTANT, you have to save the api_key code that appears in a green text box when you created successfully your API KEY, save this as your dear friend because you will need this code in the future

    Subsequently, you have to create a new python code as this:

    from qsaas.qsaas import Tenant
    import JSON
    
    api_key = <API_KEY>
    
    q = Tenant(api_key=api_key, tenant=<hostname>,
               tenant_id=<tenant_id>)
    
    q.post('reloads', json.dumps({'appId': 'dbf3e4ce-c6b3-4190-876c-c443a8691fa6'})))

    Don't worry my dear friend if you don't know where is it, the 'hostname' and the 'tenant_id' are in qlik cloud, here is a little tutorial for you:

    • First login to your qlik
    • Then click on your profile photo
    • Click in about, and there you have these two data information