Skip to main content

Official Support Articles

Search or browse our knowledge base to find answers to your questions ranging from account questions to troubleshooting error messages. The content is curated and updated by our global Support team

Announcements
Feb 9th, Qlik Product Portfolio Strategy and Roadmap Webinar for Data Integration, last chance to REGISTER

Qlik Sense: call Qlik Sense Engine API with Python

cancel
Showing results for 
Search instead for 
Did you mean: 
Damien_Villaret
Support
Support

Qlik Sense: call Qlik Sense Engine API with Python

This is a Python example to call the Qlik Sense Engine API.

Here is a simple script using the websocket-client module to call the Engine API. Note that the Qlik Sense virtual proxy is set to header authentication.

import websocket
import ssl
import json

header_user = {'header_user': 'user1'}

ws = websocket.create_connection("wss://qlikserver1.domain.local/hdr/app/", sslopt={"cert_reqs": ssl.CERT_NONE},header=header_user)

ws.send(json.dumps({
	"handle": -1,
	"method": "GetDocList",
	"params": [],
	"outKey": -1,
	"id": 1
}))

result = ws.recv()

while result:
    result=ws.recv()
    y = json.loads(result)
    print(y)

ws.close()


Example of results:

{'jsonrpc': '2.0', 'method': 'OnConnected', 'params': {'qSessionState': 'SESSION_CREATED'}}
{'jsonrpc': '2.0', 'id': 1, 'result': {'qDocList': [{'qDocName': 'test1', 'qConnectedUsers': 0, 'qFileTime': 0,
 'qFileSize': 176418, 'qDocId': '9b428869-0fba-4ba5-9f94-901ae2fdf041', 'qMeta': {'createdDate': '2018-11-29T09:28:40.588Z', 
'modifiedDate': '2018-12-17T15:13:56.860Z', 'published': True, 'publishTime': '2018-12-17T15:13:56.782Z', 
'privileges': ['read', 'offlineaccess'], 'description': '', 'dynamicColor': '', 'create': None, 'stream': {'id': 
'aaec8d41-5201-43ab-809f-3063750dfafd', 'name': 'Everyone'}, 'canCreateDataConnections': False}, 'qLastReloadTime': 
'2018-11-29T09:30:42.121Z', 'qTitle': 'test1', 'qThumbnail': {}}]}}


 

Labels (1)
Comments
beatYesterday
Contributor III
Contributor III

All,


After further research and trial and error I was able to figure out how to do this.  I'm adding the general code of how I did this below for others' reference.

 

createSessionURL = "https://host/qps/session?xrfkey=1234567890123457"

postHeaders={   "X-Qlik-User": "UserDirectory=<DIRECTORY>;UserId=<USER>",
            "X-Qlik-XrfKey": "1234567890123457",
            "Content-type":"application/json"
        }

body ="""
{
  "UserDirectory": "<DIRECTORY>",
  "UserId": "<USER>",
  "Attributes": [ ],
  "SessionId": "11111111"
}
"""

#CREATE A SESSION OBJECT
s = requests.Session()

#use created session ID to get output of Engine API exportData function, this returns a session object with the sessionID you define
r = s.post(createSessionURL, headers= postHeaders, cert =(pemPath,pemKeyPath), verify=False, allow_redirects=True, data=body)

#set headers
getHeaders = {   "X-Qlik-User": "UserDirectory=<DIRECTORY>;UserId=<USER>",
            "X-Qlik-XrfKey": "1234567890123457",
            "X-Qlik-Session": "11111111"
        }

csvURL = "https://host/tempcontent/<randomlyGeneratedPath>.csv?serverNodeId=<SERVERNODE>&xrfkey=1234567890123457'

#set Qlik Session Cookie with the same sessionID defined in post requests
s.cookies.set("X-Qlik-Session", '11111111', domain = <qlikHostDomain>)

#make call for file
r2 = s.get(csvURL, headers= getHeaders, cert =(pemPath,pemKeyPath), verify=False, allow_redirects=True)
Version history
Last update:
‎2021-02-23 04:08 AM
Updated by:
Contributors