Introduction

Platform SDK

Overview

The Qlik Platform SDK is a software development kit available in several programming languages including typescript and python that provide easy to use interfaces to Qlik Cloud APIs for managing tenants and building data analytics applications.

With the Platform SDK, you can:

  • Access the backend services of your tenants to automate tedious and repetitive tasks.
  • Build web applications on top of Qlik for managing jobs to be done across your analytics landscape.
  • Connect to Qlik Sense analytics applications and access data for use in embedded applications and machine learning models.
  • Create and explore analytics applications programatically using Qlik's unique calculation engine to solve data intensive business problems.

Get started

Installation

The Platform SDK is available in two languages today, Python and TypeScript

To install the Python version of the SDK, just use pip.

python3 -m pip install --upgrade qlik-sdk

To install the TypeScript SDK, you can use yarn or npm.

# yarn
yarn i @qlik/sdk
# npm
npm install -g @qlik/sdk

Interact with apps

In the following examples, the user only wants to interact with the Apps resource.

  • python
from qlik_sdk import Apps, AuthType, Config

apps = Apps(Config(host=base_url, auth_type=AuthType.APIKey, api_key=api_key))

# app is fetched from the REST /v1/apps/{app_id}
app = apps.get(app_id="app_id")

# opens a websocket connection against the Engine API and gets the app layout
with app.open():
    app_info = app.get_app_layout()
  • typescript
import { AuthType, Apps } from '@qlik/sdk';

const apps = new Apps({
  authType: AuthType.APIKey,
  host: base_url,
  apiKey: api_key,
});

(async () => {
  const app = await apps.get('appId');
  await app.open();
  const appLayout = await app.getAppLayout();
})();

Interceptor

Log requests using interceptors

client = Auth(Config(host=self.base_url, auth_type=AuthType.APIKey, api_key=self.api_key))
user_me = client.rest(path="/users/me")

# request interceptor method
def log_req(req: requests.Request) -> requests.Request:
    print(req)
    return req

# registers an interceptor
client.rpc.interceptors["request"].use(log_req)

app_list = client.rest(path="/items", params={"resourceType":"app", "limit": 100})

Raw calls to backend

import Qlik, { AuthType } from '../../src/qlik.js';

const { rest, rpc } = new Qlik({
  authType: AuthType.APIKey,
  host: baseUrl,
  apiKey: apiKey,
});
// raw REST call to the users endpoint
const res = await rest('/users/me');

// create an engine session and open an app with raw method
const session = rpc(appId);
const rpcSession = rpc(appId);
try {
  await rpcSession.open();
  const { handle: appHandle } = await rpcSession.send({
    handle: -1,
    method: 'OpenDoc',
    params: [appId],
  });
  await session.open()
} catch(err) { ... }

Authentication

The Platform SDK supports multiple methods for authenticating to Qlik Cloud. For backend calls, using an API key.

Using an API Key

An API key is a token representing a user in your tenant. With an API key, a user can interact with the platform programatically with the same access privileges and context they have during interactive sessions through a web browser. Follow this guide to obtain an API key for your tenant.

Once you have an API key, you can connect your backend application to Qlik Cloud using the Platform SDK to create backend applications.

from qlik_sdk import Auth, AuthType, Config

api_key = "<MY_API_KEY>"
base_url = "<URL_TO_MY_TENANT>" # E.g. https://your-tenant.eu.qlikcloud.com

auth = Auth(Config(host=base_url, auth_type=AuthType.APIKey, api_key=api_key))

Web integration ID

If you're creating an application with front-end connectivity to Qlik Cloud, you need a web integration ID to handle CORS requests. Follow this link to learn more about web integrations and head to Qlik Help for detailed instructions on how create web integration Ids for embedded analytics applications.

import { Auth, AuthType, Config } from '@qlik/sdk';

const config: Config = {
  authType: AuthType.WebIntegration,
  host: 'my-tenant.qlikcloud.com',
  webIntegrationId: '<webintegrationId>',
  autoRedirect: true, // default false
};

const auth = new Auth(config);

if (!auth.isAuthenticated()) {
  // checks the "/users/me" endpoint
  auth.authenticate(); // redirects to IDP login page
}

JWT Auth

A JWT is a digitally signed JSON web token that can be verified and trusted using a public / private key pair. JWT authorization is useful when you are embedding analytics content into portals or web applications and you want to take advantage of the host application authentication mechanism.

Follow this guide to learn how to use JWT authorization to connect to Qlik Cloud.
import { Auth, AuthType, Config } from '@qlik/sdk';

const config: Config = {
  authType: AuthType.JWTAuth,
  host: 'my-tenant.qlikcloud.com',
  webIntegrationId: '<webintegrationId>',
  fetchToken: () => Promise.resolve('<signedToken>'),
};

const auth = new Auth(config);

await auth.getSessionCookie(); // function helper for setting the session cookies.

Note: only supported in TypeScript package right now.

Was this page helpful?