Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

Highlighted
cristihainic
New Contributor III

Qlik Engine API Does Not Work after June 2017 update

Hi,

With the June 2017 upgrade of the Qlik server, most of the Qlik Engine API calls fail now (GetConnections, SetScript, GetScript, etc.). Did anyone experience this issue?

I tested the Engine API in the Engine API Explorer in the Dev Hub and the calls work there. But, using the exact same parameters through a websocket connection, the Engine API returns {'code': -32602, 'parameter': 'Invalid handle', 'message': 'Invalid Params'}

The handle and parameters I send are exactly the ones in the Engine API Explorer. Can anyone relate to this issue?

Thanks,

Chris

1 Solution

Accepted Solutions
cristihainic
New Contributor III

Re: Qlik Engine API Does Not Work after June 2017 update

I found the solution to my initial issue. It was related to not awaiting the receive() method on the websocket object created with the line from my above code: ws = await session.ws_connect(f"wss://{self.host}:{self.port}/app"). In short, when I also awaited ws.receive() everything started to work again.


Now, to explain why it worked before without calling receive() on the websocket object, I can only presume that in version 3.2, Qlik Engine did not return any message upon successfully connecting through its websocket API. And now, in version 4.0, it does. So that message had to be awaited also.

14 Replies
Employee
Employee

Re: Qlik Engine API Does Not Work after June 2017 update

You'll probably need to add the method calls you use. Can you attach an example? From the "invalid handle" string, I would suspect that there is something fishy with how you use the handle. How do you get hold of the handle and how do you use it?

cristihainic
New Contributor III

Re: Qlik Engine API Does Not Work after June 2017 update

Hi Øystein,

Sure, below flow in the client I've implemented. Everything is pretty much hardcoded, so I really can't see what is the matter.

First, I open an app by sending this:

data = {

   "jsonrpc": "2.0",
   "id": 2,
   "method": "OpenDoc",
   "handle": -1,
   "params": [

     {"qDocName": "293dght3-cd32-40ff-99afF-380e46c384a3"}

     ],
}

The server responds:

{

     'jsonrpc': '2.0',

     'id': 2,

      'result': {

          'qReturn': {

               'qType': 'Doc',

                'qHandle': 1,

                'qGenericId': '293Dght3-CD32-40FF-99AF-380E46C384A3'

     }}, 'change': [1]

}

Then, I send through the websocket connection a method such as GetConnections(), formatted as this:

data = {

     "jsonrpc": "2.0",
     "id": 2,
     "method": "GetConnections",
     "handle": 1,
     "params": [],

}

To which the server responds with an error containing the line I pasted in my question:

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

Please reply should you need any additional info on this. My initial thought was that something had changed along with the June 2017 update, because this worked perfectly (I actually got all the connections with the GetConnections() method) before updating the Qlik server.

Thank you,

Chris

Employee
Employee

Re: Qlik Engine API Does Not Work after June 2017 update

I see you are reusing the request ID. (It's set to 2 in both calls.) Don't know if that is the problem here, but I would expect those numbers to be unique. Have you tried with different ids?

cristihainic
New Contributor III

Re: Qlik Engine API Does Not Work after June 2017 update

Sure, I tried it with unique IDs, also

Employee
Employee

Re: Qlik Engine API Does Not Work after June 2017 update

I just tried to do that GetConnections operation through the .Net SDK, and it seems to work fine with the June2017 release. How do you set up the server connection in your case? Could it be that the two calls somehow go to different sessions?

Are there any methods using the app handle that you are able to run successfully?

cristihainic
New Contributor III

Re: Qlik Engine API Does Not Work after June 2017 update

As a matter of fact, no methods using the app handle (1) work. They all reply the same thing: {'code': -32602, 'parameter': 'Invalid handle', 'message': 'Invalid Params'}.

I am using a Python client to connect to the server and make the calls. This is how I connect:

async def connect(self):

  ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)

  ssl_ctx.load_cert_chain(certfile=self.certfile, keyfile=self.keyfile)

  conn = aiohttp.TCPConnector(ssl_context=ssl_ctx)

   session = aiohttp.ClientSession(connector=conn, headers={"X-Qlik-User": "UserDirectory=MyUserDirectory; UserId=MyUserId"})

   ws = await session.ws_connect(f"wss://{self.host}:{self.port}/app")

The funny thing is that this worked perfectly until upgrading to the June2017 version.

Employee
Employee

Re: Qlik Engine API Does Not Work after June 2017 update

Well, I'm afraid I'm out of ideas, but if you are familiar with C#, then you might want to try doing it through the .Net SDK and see if you get it working there. If you don't then perhaps there is some sort of server setting that has changed? You mentioned that you upgraded to June 2017, so perhaps some form of access privilege is not what it aught to be? I'm not very familiar with those settings though so just guessing...

davidcdots
New Contributor

Re: Qlik Engine API Does Not Work after June 2017 update

Hi Øystein!

I saw this discussion and I'm very interested in how do you achieve to connect with Qlik Sense Desktop sing the .Net SDK. I'm using the documented examples, but can't connect with my Qlik Sense Desktop installation:

var location = Qlik.Engine.Location.FromUri(new Uri("http://127.0.0.1:4848"));

location.AsDirectConnectionToPersonalEdition();

using(IHub hub = location.Hub())

{

     Console.WriteLine(hub.ProductVersion());

}

Problem is when trying to do location.Hub(), this throws an exception with this message:

Connection failed after 4 attempts. Error message:

  No se puede establecer una conexión ya que el equipo de destino denegó expresamente dicha conexión [::ffff:127.0.0.1]:4848

Can you guide me on how to do this? I'm following this documentation:

Getting started with the Qlik Sense .NET SDK ‒ Qlik Sense

Employee
Employee

Re: Qlik Engine API Does Not Work after June 2017 update

Just to make sure: In order to connect like that you need to have Qlik Sense Desktop up and running on your local machine, and you need to be logged in as well. Have you done that?