Skip to content

Using qlik-cli with Qlik Sense Enterprise client-managed Repository API (QRS)

Overview

This tutorial shows how to connect qlik-cli to the Qlik Sense Repository Service (QRS) in Qlik Sense Enterprise on Windows using JSON Web Token (JWT) authentication.

You will:

  1. Generate a key pair for signing JWTs.
  2. Configure a JWT virtual proxy in Qlik Sense Enterprise on Windows.
  3. Generate a signed JWT.
  4. Create a client-managed context in qlik-cli.
  5. Test the connection using a QRS command.
About Windows

Qlik Sense Enterprise on Windows is the server you are connecting to. The value windows in --server-type windows identifies that server type. You can run qlik-cli on Windows, macOS, or Linux. The command examples in this tutorial use Windows PowerShell.

Requirements

  • The latest version of qlik-cli installed on your computer. For more information, see Get started with qlik-cli.
  • A reachable Qlik Sense Enterprise on Windows site.
  • Permission to create and configure virtual proxies in the Qlik Management Console (QMC). If you don’t have the necessary permissions, ask your Qlik Sense administrator to complete the virtual proxy configuration.
  • OpenSSL to create the signing key and certificate. If OpenSSL is not available on your Windows computer, see the installation guidance in JWT authentication on Qlik Help.
  • Node.js and npm to run the local JWT generation example.
  • A Qlik Sense user ID and user directory for the user you want to authenticate as.
Caution

Configuring a virtual proxy can restart affected proxy services and interrupt active user sessions. Coordinate the change with your Qlik Sense administrator.

Step 1: Generate a key pair

Use OpenSSL to generate an RSA private key and a corresponding self-signed X.509 certificate. Run these commands in a local working directory:

Terminal window
openssl genrsa -out privatekey.pem 4096
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 1825

The second command prompts for certificate details, such as country and common name. Enter the requested values to complete certificate generation.

The files serve different purposes:

FileUsed for
privatekey.pemSigning JWTs locally. Do not upload or share it.
publickey.cerConfiguring the JWT certificate in the QMC so Qlik Sense can verify JWT signatures.

The commands are the ones used in the Qlik Sense JWT authentication instructions on Qlik Help. If openssl is not recognized on Windows, follow the OpenSSL installation guidance on this page before continuing.

If using another key-generation tool, verify that it produces a compatible signing key and X.509 certificate. An SSH public key file is not necessarily a suitable replacement for the certificate.

Step 2: Configure a JWT virtual proxy

Follow the Qlik Sense JWT authentication instructions on Qlik Help to create a JWT virtual proxy in the Qlik Management Console (QMC). They cover the administrative configuration, including session cookie settings, load balancing, the host allow list, and associating the virtual proxy with a running proxy.

For this qlik-cli example, use the following values when configuring the virtual proxy:

SettingExample valueNotes
PrefixjwtThe virtual proxy URL will be https://your-server.example.com/jwt.
Authentication methodJWTEnables JWT authentication.
JWT certificateContents of publickey.cerPaste the full certificate, including its BEGIN and END lines. Do not paste the private key.
JWT attribute for user IDuseridThis is the claim name, not an actual user ID.
JWT attribute for user directoryuserdirectoryThis is also a claim name.
Intended audienceqlik-cli-qseowMust match the JWT’s aud claim exactly.

For the remaining settings, follow Qlik Help and your site’s configuration. In particular, make sure the hostname used to access the server is allowed and that the virtual proxy is associated with a running proxy.

The Qlik Help procedure includes settings intended for testing. Review the virtual proxy’s security configuration with your Qlik Sense administrator before using it in production.

With the jwt prefix, the connection URL used later in qlik-cli is:

https://your-server.example.com/jwt

The /jwt URL identifies the virtual proxy. It is not a setup page you need to open in a browser. Follow step 5 to verify the connection and JWT authentication.

Step 3: Generate a signed JWT

Generate the token locally using the private key from step 1. Keep your private signing key secure. Do not upload it to an online JWT generator or commit it to source control.

In the directory containing privatekey.pem, install the Node.js dependency:

Terminal window
npm install jsonwebtoken

Create a file named token.js in the same directory, using the following code:

const fs = require('node:fs');
const path = require('node:path');
const jwt = require('jsonwebtoken');
// Read the private key from the same directory as this script.
const privateKey = fs.readFileSync(path.join(__dirname, 'privatekey.pem'));
// Identify the Qlik Sense Enterprise on Windows user.
const payload = {
userid: 'your-user-id',
userdirectory: 'YOUR-USER-DIRECTORY',
};
// Sign the JWT. The audience must match the virtual proxy configuration.
const token = jwt.sign(payload, privateKey, {
algorithm: 'RS256',
audience: 'qlik-cli-qseow',
expiresIn: '1h',
});
console.log(token);

Replace the two user values with the user ID and user directory shown for your Qlik Sense user in the QMC. Set audience to the intended audience configured in step 2. The jsonwebtoken library writes this value to the standard JWT aud claim.

Run the script:

Terminal window
node .\token.js

The output is a signed JWT. The example uses a one-hour lifetime for testing. Choose an expiration and token renewal process appropriate to your environment before using this setup for automation.

A signed JWT grants access as the user identified in its claims, subject to that user’s permissions. Treat it as a credential. Do not commit generated JWTs or qlik-cli context files to source control.

Step 4: Configure a client-managed context in qlik-cli

Use qlik context create to configure the client-managed server. The --api-key option accepts the signed JWT for this connection.

In PowerShell, you can capture a new token from the script without copying it into a command:

Terminal window
$jwt = node .\token.js
qlik context create QSEoW --server https://your-server.example.com/jwt --server-type windows --api-key $jwt
qlik context use QSEoW

Replace the server URL with your virtual proxy URL. The context name QSEoW is only an example. Choose any name that helps you identify the connection.

To see the configured contexts:

Terminal window
qlik context ls

Use the CLI commands to manage contexts rather than editing contexts.yml manually. This tutorial uses qlik context create for the client-managed site.

The context stores the generated JWT. When the token expires, generate a new one and update the context before running additional commands:

Terminal window
$jwt = node .\token.js
qlik context update QSEoW --api-key $jwt

Step 5: Test the connection

With the new context selected, use a QRS command to list the applications visible to the authenticated user:

Terminal window
qlik context use QSEoW
qlik qrs app ls

A successful response contains JSON with the applications accessible to the user. For example:

[
{
"id": "931d847e-b36a-4511-9547-6cc0f46b1b9c",
"name": "ConsumerSales"
}
]

The actual response contains additional properties. An empty array can also be a successful response if no applications are visible to the authenticated user.

If the request fails because the server certificate is not trusted, check the certificate configuration and trust chain.

For troubleshooting, you can temporarily bypass certificate validation:

Terminal window
qlik qrs app ls --insecure
Caution

The --insecure option disables server certificate validation. Use it only for troubleshooting, and configure certificate trust before using the connection in production.

Troubleshooting

SymptomWhat to check
Cannot connect to /jwtConfirm the hostname, virtual proxy prefix, network connectivity, and associated running proxy.
HTTP 400Check the JWT signature, expiration, aud, userid, and userdirectory claims, and the configured JWT certificate. Also check the host allow list and hostname used in the request.
HTTP 404Check the virtual proxy prefix in the server URL. For example, /jwtx instead of /jwt returned HTTP 404 during testing.
HTTP 403 from a QRS commandCheck the authenticated user’s permissions for the requested QRS resource.
Certificate validation errorVerify the server’s HTTPS certificate and whether its issuing CA is trusted on the computer running qlik-cli.
Qlik Cloud commands work but QRS commands failConfirm that the client-managed context is selected and that you are using a qlik qrs command.

Next steps

Use the built-in CLI help to explore the QRS commands available in your installed version:

Terminal window
qlik qrs --help
qlik qrs app --help

For general context management, see Authenticate to Qlik using qlik-cli contexts.

Was this page helpful?