Skip to content

Overview - Platform SDK

This toolkit for Python is in public preview. The Typescript version is deprecated. Please use the @qlik/api as a replacement for the Typescript SDK.

The Qlik Platform SDK is currently in a public preview. Please expect frequent updates and at times breaking changes as feedback is incorporated between releases. Please follow the changelog for updates. 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 programmatically 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 programmatically 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))

OAuth2

OAuth is a standard security protocol for authorization and delegation. It allows third party applications to access API resources without disclosing the end-user credentials.

For a step-by-step guide on how to create an OAuth client for your tenant, see Create an OAuth client.

import enigma from "enigma.js";
import schema from "enigma.js/schemas/12.936.0.json";
import { Auth, AuthType, Config } from "@qlik/sdk";

const config: Config = {
  authType: AuthType.OAuth2,
  host: "your-tenant.us.qlikcloud.com",
  clientId: "<clientId>",
  clientSecret: "<clientSecret>", // only used for OAuth client configuration type Web
  redirectUrl: "<redirectUrl>",
  scopes: ["<scopes>"], // offline_access can be added for using reauthorization
  // Note: offline_access is not allowed for OAuth client configuration type SPA
};

const auth = new Auth(config);

if (!(await auth.isAuthorized())) {
  // check if the current web-app has already been authorized.
  const { url } = await auth.generateAuthorizationUrl(); // generate the url needed for for the OAuth exchange token flow
  window.location = url;
}
// ....
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get("code");
if (code) {
  // it has been redirected
  await auth.authorize(window.location.href); // exchanges the credentials for a token
  // ....
  // websocket url for Enigma.js
  const wsUrl = await generateWebsocketUrl(appId);
  const session = enigma.create({
    schema,
    createSocket: () => new WebSocket(wsUrl),
  });
}
// other available methods for the OAuth flow are:
await auth.deauthorize();
await auth.reauthorize();

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 for detailed instructions on how to create web integration IDs for embedded analytics applications.

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

const config: Config = {
  authType: AuthType.WebIntegration,
  host: "your-tenant.us.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: "your-tenant.us.qlikcloud.com",
  webIntegrationId: "<webintegrationId>",
  fetchToken: () => Promise.resolve("<signedToken>"),
};

const auth = new Auth(config);

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

Note: Currently, JWT authorization is only supported in the TypeScript package.

Was this page helpful?