Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now

Make API calls in a Qlik Sense on Windows Script

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Juli_K
Former Employee
Former Employee

Make API calls in a Qlik Sense on Windows Script

Last Update:

Mar 18, 2022 9:55:41 AM

Updated By:

Sonja_Bauernfeind

Created date:

Apr 5, 2018 9:41:51 AM

Typically the Qlik REST Connector is used for situations where data will be returned and used within a Qlik Sense App. Use cases have been described where it is ideal to be able to perform actions like starting a Qlik Sense Task depending on if certain values are returned by other Data Connections. This would usually be scripted outside of the Qlik Sense script using our API endpoints. However, with minor changes, it can be performed inside the Qlik Sense script itself.

Environment:

Qlik Sense Enterprise on Windows 

 

Resolution

 

Prerequisites:

 

Configuring the REST Connection:

  1. For my use case, the goal is to start a Qlik Sense Task. The endpoint used is https://<ServerName>:4242/qrs/task/start?name=<TaskName>; which uses a POST request that returns no data.
  2. The Authentication Schema is 'Anonymous'
  3. The exported Client.pfx certificate was added to the request
  4.  For the Additional request parameters:
    1. Query parameters needs the xrfkey - value included e.g. xrfkey -  ichbineinberlinR
    2. Query headers needs X-Qlik-XrfKey and X-Qlik-User headers included e.g. X-Qlik-XrfKey - ichbineinberlinR  and X-Qlik-User - UserDirectory=internal; UserId=sa_api
  5. If the parameters are correct, clicking either the Test Connection or Save buttons will not error but instead perform the API Request

 

Making the call within the script:

Typically, after making a new Data connection, the 'Select Data' button would be used to select the fields that would be added to the script. In my use case, the endpoint I used returns no values so there was nothing to add to the script. To use this new data connection in the script, the Connector needs to think it will be searching for Data and hit our endpoint looking for this data. I added the following query to my script that returns no data from a non-existent "Root" table:

 

LIB CONNECT TO 'Trigger Task';
RestTable:
SQL SELECT 
FROM JSON (wrap on) "Root";
Drop Table RestTable;

 

Now, when the document is reloaded, the endpoint will be hit (my task will be reloaded), no data will be returned, a table will be created/dropped and the rest of the script will be run.

 

Advanced:

Here is a more advanced script that will allow you to dynamically change the URL with variables:

In the Data connection created, check the "Add missing parameter to final request" check box to ensure the xrfkey query parameter will be added to the custom URL

 

Let vServer = 'localhost';
Let vTaskName = 'Reload Operation Monitor';

Let vURL = '"https://$(vServer):4242/qrs/task/start?name=$(vTaskName) "';

LIB CONNECT TO 'Trigger Task';
RestTable:
SQL SELECT
FROM JSON (wrap on) "root"
WITH CONNECTION ( URL $(vURL) );
Drop Table RestTable;

 

 

API Call in Qlik Script.gif

Labels (2)
Comments
Sonja_Bauernfeind
Digital Support
Digital Support

Hello @jpjust 

Please post about your issue in the appropriate forum: Qlik Sense Integration, Extensions, & APIs.

All the best,
Sonja 

Contributors
Version history
Last update:
‎2022-03-18 09:55 AM
Updated by: