Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
virilo_tejedor
Creator
Creator

Can't do app reload using Engine API

Hi,

I’d like to reload a POC application in QlikSense Desktop.

It should be done in Python, due to there are related process which has been developed on this language.

When I called the WebSocket I got the next error:

{

"jsonrpc":"2.0",

"id":3,

"error":{

"code":-32602,

"parameter":"Invalid handle",

"message":"Invalid Params"

}

}

I have used this Python code:

from websocket import create_connection

qlik_ws_url = "ws://127.0.0.1:4848/app/C%3A%5CUsers%5Cvirilo.tejedor%5CDocuments%5CQlik%5CSense%5CApps%5CPOC.qvf"

qlik_ws_url="ws://localhost:4848/app/jbGFs"

ws = create_connection(qlik_ws_url)

# 1st try

"""

params='''{"handle": "1",

    "method": "DoReload",

  "params": {

  "qMode": "0",

  "qPartial": "false",

  "qDebug": "false"

  }}'''

"""

params='''{

  "handle": 1,

  "method": "DoReload",

  "params": {

  "qMode": 0,

  "qPartial": "false",

  "qDebug": "false"

  },

  "jsonrpc": "2.0",

  "id": 3

}'''

print("params:")

print(params)

ws.send(params)

print ("Sent")

print ("Receiving...")

result =  ws.recv()

print ("Received '%s'" % result)

ws.close()

I already did successfully a WebSocket call with the same python code to GetDocList remote procedure, using params = "{\"method\":\"GetDocList\",\"handle\":-1,\"params\":[],\"id\":7,\"jsonrpc\":\"2.0\"}"; 

I tried several combinations of url for the endpoint.  I got the application id following this instructions: https://help.qlik.com/en-US/sense-developer/3.0/Subsystems/Mashups/Content/Howtos/mashups-obtain-app...

Any help will be welcomed.

Thanks in advance,

Virilo

1 Solution

Accepted Solutions
Alexander_Thor
Employee
Employee

A Engine session can only open a app once, if you try to call OpenDoc in a engine session that already has a document opened that's when you get the "App already opened" error. And since you have the app opened in the same session in Desktop you won't be able to call OpenDoc from your program.

However you can easily check for that error and instead call GetActiveDoc which will return you a handle the currently opened document.

GetActiveDoc method ‒ Qlik Sense

View solution in original post

9 Replies
websy1985
Luminary Alumni
Luminary Alumni

Hi Virilo,

Looks like you have an active connection but you haven't opened the app. Try calling the "OpenDoc" method and passing in your appname as a parameter -

http://help.qlik.com/en-US/sense-developer/3.1/Subsystems/EngineAPI/Content/Classes/GlobalClass/Glob...

The response from that will give you the doc handle and you can then call DoReload.

I hope that helps.

Thanks

Nick

virilo_tejedor
Creator
Creator
Author

Hi Nick,

Thanks for your answer!

I used OpenDoc before the ReLoad, and it worked.

But once the application is opened via Desktop application, the same error is returned.

These are the responses obtained doing DoReload call with QlikDestop started and no application opened:

            params:

            {

                   "handle": -1,

                   "method": "OpenDoc",

                   "params": {

                           "qDocName": "POC.qvf",

                           "qUserName": "",

                           "qPassword": "",

                           "qSerial": "",

                           "qNoData": false

                   }

            }

            Sent

            Receiving...

            Received '{"jsonrpc":"2.0","id":0,"result":{"qReturn":{"qType":"Doc","qHandle":1}},"change":[1]}'

            params:

            {

                   "handle": 1,

                   "method": "DoReload",

                   "params": {

                           "qMode": 0,

                           "qPartial": false,

                           "qDebug": false

                   },

                   "jsonrpc": "2.0",

                   "id": 3

            }

            Sent

            Receiving...

            Received '{"jsonrpc":"2.0","id":3,"result":{"qReturn":true},"change":[1]}'          

Responses when QlikDestop is started and the application opened:

                params:

                {

                        "handle": -1,

                        "method": "OpenDoc",

                        "params": {

                                "qDocName": "POC.qvf",

                                "qUserName": "",

                                "qPassword": "",

                                "qSerial": "",

                                "qNoData": false

                        }

                }

                Sent

                Receiving...

                Received '{"jsonrpc":"2.0","id":0,"error":{"code":1002,"parameter":"POC.qvf","message":"App already open"}}'

                params:

                {

                        "handle": 1,

                        "method": "DoReload",

                        "params": {

                                "qMode": 0,

                                "qPartial": false,

                                "qDebug": false

                        },

                        "jsonrpc": "2.0",

                        "id": 3

                }

                Sent

                Receiving...

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

Python code with the OpenDoc call:

        from websocket import create_connection

       

        #qlik_ws_url="ws://localhost:4848/app/jbGFs"

        qlik_ws_url = "ws://localhost:4848/app/        C%3A%5CUsers%5Cvirilo.tejedor%5CDocuments%5CQlik%5CSense%5CApps%5CPOC.qvf"

       

       

        ws = create_connection(qlik_ws_url)

       

        params='''{

        "handle": -1,

        "method": "OpenDoc",

        "params": [

        "POC.qvf"

        ],

        "outKey": -1

        }'''

       

        print("params:")

        print(params)

       

        ws.send(params)

        print ("Sent")

        print ("Receiving...")

        result =  ws.recv()

        print ("Received '%s'" % result)

       

       

       

        params='''{

        "handle": 1,

        "method": "DoReload",

        "params": {

        "qMode": 0,

        "qPartial": false,

        "qDebug": false

        },

        "jsonrpc": "2.0",

        "id": 3

        }'''

       

       

        print("params:")

        print(params)

       

        ws.send(params)

        print ("Sent")

        print ("Receiving...")

        result =  ws.recv()

        print ("Received '%s'" % result)

       

        ws.close()

Using Engine Api Explorer app at http://127.0.0.1:4848/dev-hub/engine-api-explorer it is possible to do the reload, even when the application is already opened by Desktop application.

Any suggestion?

Best regards,

Virilo

Alexander_Thor
Employee
Employee

Make sure you call DoSave to persist your changes and new data.

DoSave method ‒ Qlik Sense

virilo_tejedor
Creator
Creator
Author

Hi Alexander,

I improved the code with the DoSave call.  Now changes are persisted after reload.

But the main problem still remains: the script runs successfully only when the application is closed.

If the POC.qvf application is opened by QlikSense Desktop vía Windows application or by Engine API Explorer, the Python WebSocket call fails returning "App already open".

This time the error message is very clear, but it should be possible to do a reload even with the application opened.

Al least, I can do it using WebSockets from a HTML client, doing the following steps:

  1. Open POC.qvf on QlikSense Desktop
  2. Open POC application on Engine API Explorer at http://127.0.0.1:4848/dev-hub/engine-api-explorer    Now, the application is simultaneously opened in both QlikSense Desktop and Engine API Explorer applications
  3. Do the ReLoad call via WebSocket using Engine API Explorer: Ok is returned
  4. When I go back to QlikSense Desktop, and the opened application has the new data, and informs the user that there are new changes pending to be saved.

But doing the same using the Python WebSocket call, it fails on step 2:

  1. Open POC.qvf on QlikSense Desktop
  2. Open POC application vía WebSocket using Python script, method= "method": "OpenDoc".  It fails, "message":"App already open"
  3. Do the ReLoad call via WebSocket using Python script: error is returned, due to the app wasn’t correctly opened

What could be happening?

Is there any alternative to open POC.qvf application from Python WebSocket in a concurrent way?

Best regards,

Virilo

Alexander_Thor
Employee
Employee

A Engine session can only open a app once, if you try to call OpenDoc in a engine session that already has a document opened that's when you get the "App already opened" error. And since you have the app opened in the same session in Desktop you won't be able to call OpenDoc from your program.

However you can easily check for that error and instead call GetActiveDoc which will return you a handle the currently opened document.

GetActiveDoc method ‒ Qlik Sense

virilo_tejedor
Creator
Creator
Author

Problem solved. Thanks a lot!

Best regards,

Virilo

marcos_herrera
Partner - Creator III
Partner - Creator III

Hi dear Virilo

Thanks for the post, was wonderful for me, I have a problem with DoReload method, the result response is parameter invalid, I'm using your code and verified the parameters with API explorer and are well, I don't know what is the error, Can you Help me? Please

 

 

 

 

 

marcos_herrera
Partner - Creator III
Partner - Creator III

Hi dear Virilo

 

See the images with code and errorCode.PNG

Error.PNG

marcos_herrera
Partner - Creator III
Partner - Creator III

Hi Dear friends
I used Virilio's code and create the following code to Open, ActiveDocument, Reload and save, the last option (share) i'm  getting better because still fail, if is possible can you review and help me  to solve the issue


from websocket import create_connection
import time
qlik_ws_url = "ws://localhost:4848/app/C%3A%5CUsers%5CMarcos%20Herrera%5CDocuments%5CQlik%5CSense%5CApps%5C00_App.qvf"

# qlik_ws_url="ws://localhost:4848/app/jbGFs"
print("Conecting to QS")
ws = create_connection(qlik_ws_url)
print("Conected")
################################################################################
print("Opening Doc...")
params = '''{
"handle": -1,
"method": "OpenDoc",
"params": [
"00_App.qvf"
],
"outKey": -1
}'''
print("params:")
print(params)
ws.send(params)
print("Sent OpenDoc")
print("Receiving OpenDoc...")
result = ws.recv()
print("Received OpenDoc '%s'" % result)
################################################################################
print("###########################GetActiveDoc#####################################################")
params = '''{
"handle": -1,
"method": "GetActiveDoc",
"params": {}
}
'''
print("params:")
print(params)
ws.send(params)
print("Sent GetActiveDoc")
print("Receiving GetActiveDoc...")
result = ws.recv()
print("Received '%s'" % result)
################################################################################
print("###########################Reloading Doc#####################################################")
params = '''{"handle": 1,"method": "DoReload","params": {"qMode": 0,"qPartial": false,"qDebug": false}}'''
print("params:")
print(params)
ws.send(params)
print("Sent DoReload")
print("Receiving DoReload...")
result = ws.recv()
time.sleep(5)
print("Received '%s'" % result)
################################################################################
print("###########################Saving Doc#####################################################")
params = '''{"handle": 1,"method": "DoSave","params": {"qFileName": ""}}'''
print("params:")
print(params)
ws.send(params)
print("Sent Saving Doc")
print("Receiving Saving Doc...")
result = ws.recv()
print("Received '%s'" % result)
ws.close()


This is the answer of DocSave Method:
Received '{"jsonrpc":"2.0","id":0,"result":{"qReturn":true},"change":[1]}'

But the document not save, if you verify the modified date on File Explorer not change, another interesting thing is if you compare the answer on Python vs Answer on Engine Api Explorer if the same, but when you execute on API Enginee Explored worked