Skip to content

Access lists of bookmarks (Platform SDK)

qlik/api: The typescript platform SDK used in this tutorial has been deprecated. Review how to transition to qlik/api.

Introduction

In this tutorial, you are going to learn how to list bookmarks in a Qlik Sense application with the Platform SDK.

Requirements

Variables you need to complete this tutorial

  • host: The hostname for your Qlik Cloud tenant (for example hello.us.qlikcloud.com)
  • clientId: The clientId for the machine-to-machine OAuth client
  • clientSecret: The clientSecret for the machine-to-machine OAuth client
  • appId The appId is the unique identifier (guid) for the application you want to connect to.

Authorize a connection to Qlik Cloud

Configure a Nodejs application and add the @qlik/sdk package using NPM.

npm install @qlik/sdk

Create a file named bookmark-list.js file of your application you want to use the sdk, import the Qlik and AuthType modules from the sdk.

const Qlik = require('@qlik/sdk').default;
const { AuthType } = require("@qlik/sdk");

Update the configuration values with the variables identified earlier in the tutorial.

const host = process.env['host'] // "<tenant.region.qlikcloud.com>";
const clientId = process.env['clientId'] // "<OAUTH_CLIENT_ID>";
const clientSecret = process.env['clientSecret'] //"<OAUTH_CLIENT_SECRET>";
const appId = process.env['appId'] // "<APPID_GUID_LIKE_THIS_b1b79fcd-e500-491c-b6e9-2ceaa109214c";

Configure authorization to Qlik. This example uses a machine-to-machine OAuth token to connect to Qlik Cloud.

const config =  {
  authType: AuthType.OAuth2,
  host: host,
  clientId: clientId,
  clientSecret: clientSecret
};

List bookmarks

Begin with an async function to immediately execute this snippet. The remainder of the code goes in between the curly {} braces.

(async () => {})();

Establish a connection to your Qlik Cloud tenant.

  const qlik = new Qlik(config);
  await qlik.auth.authorize();

Get a reference to the Qlik Sense application to open and open it.

  const app = await qlik.apps.get(appId);
  await app.open();

Call the getBookmarks() function with a JSON payload containing the following structure and values.

  const bList = await app.getBookmarks({
    qTypes: ["bookmark"],
    qData: {
      title: "/qMetaDef/title",
      description: "/qMetaDef/description",
      sheetId: "/sheetId",
      selectionFields: "/selectionFields",
      creationDate: "/creationDate",
    },
  });

  • qTypes: an array of strings containing the object types you want in the response. In this case bookmark.
  • qData: Identifies the metadata to include for each bookmark returned in the list.
    • title: The property returns the title of the bookmark. Value is "/qMetaDef/title"
    • description: Returns the description property of the bookmark. Value is: "/qMetaDef/description"
    • sheetId: Returns the sheet object identifier if the bookmark is associated with a sheet in the app. Value is: "/sheetId"
    • selectionFields: Returns the fields the bookmark will select from when the bookmark is applied. Value is: "/selectionFields"
    • creationDate: Returns the date the bookmark was created. Value is: "/creationDate"

Evaluate the bookmark list by sending it to the console.

  console.log(bList);

RUn the script by opening a terminal shell and issuing the command node bookmark-list.js. The console output will return an array of bookmark objects. Here is an example of a bookmark definition returned in the list.

NxContainerEntry {
    qData: JsonObject {
      qBookmark: [Object],
      title: 'hello-bookmark',
      description: 'Hello! This is a bookmark created with a snippet from qlik.dev.',
      sheetId: '',
      selectionFields: '',
      creationDate: '2023-04-07T00:31:23.847Z'
    },
    qInfo: NxInfo {
      qId: '<bookmarkId>',
      qType: 'bookmark'
    },
    qMeta: NxMeta {
      qName: 'hello-bookmark',
      title: 'hello-bookmark',
      description: 'Hello! This is a bookmark created with a snippet from qlik.dev.',
      isExtended: true,
      _resourcetype: 'app.object',
      _objecttype: 'bookmark',
      id: '<bookmarkId>'
      approved: false,
      published: true,
      owner: '<UserSubject>',
      ownerId: '<UserId>',
      createdDate: '2023-04-07T00:31:24.001Z',
      modifiedDate: '2023-04-07T00:31:24.466Z',
      publishTime: '2023-04-07T00:31:24.466Z',
      privileges: [Array]
    }
  },

Next steps

Now that you have a list of bookmarks, you may want to apply it programmatically and evaluate the data that’s selected as a result. Check out this tutorial on applying a bookmark from code.

Full code snippet

//bookmark-list.js
//List published and bookmarks owned by the user
//Authorizes through OAuth2 M2M to connect to a Qlik Cloud application.
//To create an OAuth client for this snippet, go here:
//https://qlik.dev/authenticate/oauth/create/create-oauth-client
//To use a sample app with this snippet, download and import the executive
//dashboard from this github location https://github.com/qlik-oss/qlik-cloud-examples/raw/main/qlik.dev/sample-apps/qlik-dev-exec-dashboard.qvf
/*PARAMS
* host: the hostname of your tenant
* clientId: the clientId of the OAuth2 client you created
* clientSecret: the client secret for the OAuth2 client you created
* appId: The GUID for the Qlik Sense app
*/

//Uncomment below if you're using this code with https://repl.it
//global.fetch = require('@replit/node-fetch');

const Qlik = require('@qlik/sdk').default;
const { AuthType } = require("@qlik/sdk");

//config-values
const host = process.env['host'] // "<tenant.region.qlikcloud.com>";
const clientId = process.env['clientId'] // "<OAUTH_CLIENT_ID>";
const clientSecret = process.env['clientSecret'] //"<OAUTH_CLIENT_SECRET>";
const appId = process.env['appId'] // "<APPID_GUID_LIKE_THIS_b1b79fcd-e500-491c-b6e9-2ceaa109214c";

const config =  {
  authType: AuthType.OAuth2,
  host: host,
  clientId: clientId,
  clientSecret: clientSecret
};

(async () => {
  const qlik = new Qlik(config);
  await qlik.auth.authorize();
  const app = await qlik.apps.get(appId);
  await app.open();
  const bList = await app.getBookmarks({
    qTypes: ["bookmark"],
    qData: {
      title: "/qMetaDef/title",
      description: "/qMetaDef/description",
      sheetId: "/sheetId",
      selectionFields: "/selectionFields",
      creationDate: "/creationDate",
    },
  });
  console.log(bList);
  process.exit();
}
)();

Was this page helpful?