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:
- Generate a key pair for signing JWTs.
- Configure a JWT virtual proxy in Qlik Sense Enterprise on Windows.
- Generate a signed JWT.
- Create a client-managed context in qlik-cli.
- Test the connection using a QRS command.
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.
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:
openssl genrsa -out privatekey.pem 4096openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 1825The 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:
| File | Used for |
|---|---|
privatekey.pem | Signing JWTs locally. Do not upload or share it. |
publickey.cer | Configuring 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:
| Setting | Example value | Notes |
|---|---|---|
| Prefix | jwt | The virtual proxy URL will be https://your-server.example.com/jwt. |
| Authentication method | JWT | Enables JWT authentication. |
| JWT certificate | Contents of publickey.cer | Paste the full certificate, including its BEGIN and END lines. Do not paste the private key. |
| JWT attribute for user ID | userid | This is the claim name, not an actual user ID. |
| JWT attribute for user directory | userdirectory | This is also a claim name. |
| Intended audience | qlik-cli-qseow | Must 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/jwtThe /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:
npm install jsonwebtokenCreate 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:
node .\token.jsThe 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:
$jwt = node .\token.jsqlik context create QSEoW --server https://your-server.example.com/jwt --server-type windows --api-key $jwtqlik context use QSEoWReplace 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:
qlik context lsUse 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:
$jwt = node .\token.jsqlik context update QSEoW --api-key $jwtStep 5: Test the connection
With the new context selected, use a QRS command to list the applications visible to the authenticated user:
qlik context use QSEoWqlik qrs app lsA 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:
qlik qrs app ls --insecureThe --insecure option disables server certificate validation.
Use it only for troubleshooting, and configure certificate trust before using the connection in production.
Troubleshooting
| Symptom | What to check |
|---|---|
Cannot connect to /jwt | Confirm the hostname, virtual proxy prefix, network connectivity, and associated running proxy. |
| HTTP 400 | Check 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 404 | Check the virtual proxy prefix in the server URL. For example, /jwtx instead of /jwt returned HTTP 404 during testing. |
| HTTP 403 from a QRS command | Check the authenticated user’s permissions for the requested QRS resource. |
| Certificate validation error | Verify 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 fail | Confirm 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:
qlik qrs --helpqlik qrs app --helpFor general context management, see Authenticate to Qlik using qlik-cli contexts.