Qlik Community

Integration, Extension & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Support Case Portal has moved to Qlik Community! Read the FAQs to start exploring Support resources.
cancel
Showing results for 
Search instead for 
Did you mean: 
cristihainic
Contributor III
Contributor III

Qlik Engine API - how to make requests? [Python / Twisted]

Hi everyone,

I've managed perfectly fine to interact with Qlik Engine via the Engine API Explorer. However, I cannot figure out how to make Engine API calls programmatically. I am using Python with the Twisted library for interacting with websocket servers.

Say I want to do a simple request, e.g. CreateApp. Upon establishing a connection via a Twisted protocol, I am trying to send the following request by that protocol's transport.write() method:

TEST_LOAD = {

  "handle": -1,
  "method": "CreateApp",
  "params": {

  "qAppName": "Test-App",
  "qLocalizedScriptMainSection": ""
  },
  "jsonrpc": "2.0",
  "id": 5
}

class QlikClient(Protocol):

  def connectionMade(self):

  self.transport.write(bytes(json.dumps(TEST_LOAD), encoding='utf-8'))

  print('Sent ', json.dumps(TEST_LOAD), 'to the server.')

  def dataReceived(self, data):

  print("Server said:", data)

  self.transport.loseConnection()

The problem is that the Qlik server does not respond. So I am not sure if this is the correct way of sending Qlik Engine requests. The Twisted protocol is built and the connection seems to be established, however I have no reply from the server.

Could anyone please suggest how I could make a proper request to the Qlik Engine API?

Please note that I am using client certificates copies stored locally for authentication.

Thank you,

Chris

1 Solution

Accepted Solutions
cristihainic
Contributor III
Contributor III
Author

Hi Ariel.

Aiohttp also handles HTTPS connections, yes, but here we are addressing the Qlik Engine API, which is a websocket server. So I needed to build a websocket client. There is no code out there on the internet that can walk you through this, unfortunately, especially with Python. But you can read about connecting to the Engine API here: Connecting to the Qlik Engine API ‒ Qlik Sense . Personally I am using Qlik Sense Enterprise and connecting directly using certificates. Below is the Python process I am using.

So what I did for authentication was to use a certificate file (e.g., "client.pem") and a certificate key file (e.g., "key_client.pem"), which my company had generated from the server hosting our Qlik instance. I loaded these two files into the ssl context certification chain (using Python's ssl module) and then created a connection using aiohttp's TCPConnector, passing the ssl context as an argument. Then I created an aiohttp.ClientSession using the aforementioned connection as a connector. Finally, I called the ws_connect() method of the ClientSession, passing as an argument a websocket address formatted as follows: wss://<host>:<port>/app

And the connection was finally made. I could then call the various Engine API methods. I cannot release any code from the project I am working on, but this is the general process for establishing a connection. I found Qlik APIs to be particularly user-UNfriendly, so the best you can do is arm yourself with patience and work it out piece by piece. As you can see, this question was asked in March and I'm still having trouble figuring out how to use the Engine API to its full capabilities.

View solution in original post

6 Replies
arieidel
Partner
Partner

Hello Cristian,

Have you managed to solve this issue?

Thanks,

Ariel

cristihainic
Contributor III
Contributor III
Author

Hi Ariel. I quit using Twisted for this. I found that creating apps works fine with Python's aiohttp module and its websocket capabilities.

arieidel
Partner
Partner

Hi Cristian,

Does aiohttp accept https connections?

I also kindly ask you if you can share any script for authenticate to Qlik Sense Server or a page where I can look at.

Thanks!

Ariel

cristihainic
Contributor III
Contributor III
Author

Hi Ariel.

Aiohttp also handles HTTPS connections, yes, but here we are addressing the Qlik Engine API, which is a websocket server. So I needed to build a websocket client. There is no code out there on the internet that can walk you through this, unfortunately, especially with Python. But you can read about connecting to the Engine API here: Connecting to the Qlik Engine API ‒ Qlik Sense . Personally I am using Qlik Sense Enterprise and connecting directly using certificates. Below is the Python process I am using.

So what I did for authentication was to use a certificate file (e.g., "client.pem") and a certificate key file (e.g., "key_client.pem"), which my company had generated from the server hosting our Qlik instance. I loaded these two files into the ssl context certification chain (using Python's ssl module) and then created a connection using aiohttp's TCPConnector, passing the ssl context as an argument. Then I created an aiohttp.ClientSession using the aforementioned connection as a connector. Finally, I called the ws_connect() method of the ClientSession, passing as an argument a websocket address formatted as follows: wss://<host>:<port>/app

And the connection was finally made. I could then call the various Engine API methods. I cannot release any code from the project I am working on, but this is the general process for establishing a connection. I found Qlik APIs to be particularly user-UNfriendly, so the best you can do is arm yourself with patience and work it out piece by piece. As you can see, this question was asked in March and I'm still having trouble figuring out how to use the Engine API to its full capabilities.

View solution in original post

moa_sakthi
Contributor
Contributor

Hi Cristian ,

Can you please share the sample code. To connecting Engine API through websocket using Python.

socketOptions = {"ca_certs": "client.pem","keyfile":"client_key.pem", "certfile": "root.pem")}

websocket.enableTrace(True)

ws = websocket.WebSocketApp(wss://localhost/app, on_message= message,on_error =error , on_close = close)

ws.run_forever(sslopt=socketOptions)


It's not connecting anymore ? its show like key_value mismatch..!

But when i check using openssl , both are same ?


what's with wrong in above code ? Can please you help me out in this ?


Thanks in advance ... !

cristihainic
Contributor III
Contributor III
Author

did it connect before?