6 Replies Latest reply: Dec 15, 2016 3:50 AM by Virilo Tejedor RSS

    Can't do app reload using Engine API

    Virilo Tejedor

      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-object-id.htm

       

      Any help will be welcomed.

       

      Thanks in advance,

       

      Virilo

        • Re: Can't do app reload using Engine API
          Nick Webster

          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/Global-class-OpenDoc-method.htm

           

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

           

          I hope that helps.

           

          Thanks

          Nick

            • Re: Can't do app reload using Engine API
              Virilo Tejedor

              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

                • Re: Can't do app reload using Engine API
                  Alexander Karlsson

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

                  DoSave method ā€’ Qlik Sense

                    • Re: Can't do app reload using Engine API
                      Virilo Tejedor

                      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