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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
hsonnino
Contributor
Contributor

QlikSense Engine API with Python requests lib

Hi all,

I've been trying for quite some time now to send requests to QlikSense engine without success.
I must say that using the Engine API explorer works great, but I need the same functionality in a Python script.

The actions I need to be done are very specific:
1. Get a script from txt file (GetIncludeFileContent method)
2. Choose an app (OpenDoc method)
3. Set the script to the one we got from section no.1 (SetScript method)

I have used the sample code from https://support.qlik.com/articles/000061628, and it worked fine:
I did get all my apps list - but any request I'm sending, I'm still getting a response with the app list.

These are the sample headers:
headers = {'X-Qlik-xrfkey': xrf,
"Content-Type": "application/json",
"User-Agent":"Windows"}

res = requests.get(url,headers = headers,verify=False,auth=user_auth)

If I want to addthis:
{
"method": "OpenDoc",
"handle": -1,
"params": [
"app_id_example123456"
],
"outKey": -1,
"id": 2
}

How can I add this to the request?
Are all these methods (GetIncludeFileContent, OpenDoc, SetScript) should use "GET" ? 

If someone has a Python script to share - it would be great!

Thanks

 

Labels (3)
2 Replies
lorenzoconforti
Specialist II
Specialist II

The following works for me; you should be able to adapt it to your needs:

 

import websocket
import ssl
import json

header_user = {'header_user': 'user1'}

ws = websocket.create_connection("ws://localhost:4848/app/", header=header_user)

print("connect")
print(ws.recv())


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

print("receiving list")
print(ws.recv())

ws.send(json.dumps({
"method": "OpenDoc",
"handle": -1,
"params": [
"C:\\Users\\AndreonL\\Documents\\Qlik\\Sense\\Apps\\AgingTable.qvf"
],
"outKey": -1,
"id": 2
}))

print("open doc")
print(ws.recv())

ws.send(json.dumps({
"handle": 1,
"method": "GetScript",
"params": {},
"outKey": -1,
"id": 3
}))

print("get script")
print(ws.recv())

 

ws.close()

niraj8241
Contributor II
Contributor II

When running the last "GetScript" thing. I get the below error. Any idea why?

{"jsonrpc":"2.0","id":4,"error":{"code":-32602,"parameter":"Invalid handle","message":"Invalid Params"}}