3 Replies Latest reply: Sep 8, 2015 11:02 AM by Alexander Karlsson RSS

    Start with Qlik Engine API

    Halmar Heijnen

      Hi All,

       

      The Qlik Engine API part of the help site is very usefull, but I miss the part before the start....

       

      How do I create the basic HTML-file where I can add the functions?

       

      I started with the easy one: Create a new QVF-file, using qsocks:

      <!DOCTYPE html>  <meta charset="utf-8" /> 
      
      
      <title>CreateAppTest</title> 
      
      
      <script language="javascript" type="text/javascript">
      
      
      <script src="https://rawgit.com/mindspank/qsocks/master/qsocks.bundle.js"></script>
      <script>
      
      
        qsocks.Connect().then(function(global) {
          console.log(global)
      
      
        {
        "jsonrpc": "2.0",
        "id": 0,
        "method": "CreateApp",
        "handle": -1,
        "params": [
        "CreateNewAppTest.qvf"
        ]
      }
        });
      
      </script>
      
      

       

      I saved it as a HTML-file and opened it in Chrome.....and nothing happened, what do I miss or what am I doing wrong?

       

      THANKS!

       

      Halmar

        • Re: Start with Qlik Engine API
          Alexander Karlsson

          Hey Halmar,

          So, just to get the terminology correct. The Engine API (Built by Qlik) is our communication protocol that follows the JSON RPC specification. Meaning the Engine API can be used in every programming language that supports sockets and json.

           

          qsocks (Not a Qlik product) is a javascript implementation of the Engine API that adds a promise layer on top of the calls back and forth with the engine. You can find more examples and documentation at mindspank/qsocks · GitHub even though all the methods will be the same as the Engine API.

           

          So in your case you would never actually construct the JSON message the is sent to the Engine, qsocks will take care of that for you. You would just call the methods on the scope/context/class you are operating on and pass whatever parameters the method requires.

           

          Here is for example a working example that will connect to Qlik Sense Desktop and create a app.
          It's verbose but should get you started, will also run without a web a server

           

           

          <script src="https://rawgit.com/mindspank/qsocks/master/qsocks.bundle.js"></script>
          <script>
          
          
            qsocks.Connect().then(function(global) {
            document.body.innerText = 'Connected'
          
            // We now have access to the global class. See the documentation here for available methods
            // https://help.qlik.com/sense/2.0/en-us/developer/Subsystems/EngineAPI/Content/Classes/GlobalClass/Global-class.htm
          
            global.createApp('QlikCommunityTest.qvf').then(function(reply) {
            document.body.innerText = 'App has been created ' + JSON.stringify(reply)
            }, function(error) {
            document.body.innerText = 'Failed to create app ' + JSON.stringify(error)
            })
          
          
            }, function(error) {
             document.body.innerText = 'Failed to connect to Qlik Sense Desktop ' + JSON.stringify(error)
            });
          
          
          </script>
          <body></body>
          
            • Re: Start with Qlik Engine API
              Halmar Heijnen

              Ok Alexander, that works!

               

              But now I want to execute an action that is a little bit harder.

              The createapp function has clear parameters, but the createdimension hasn't clear dimensions.

               

              I wanted to add a master item.

              I.e. a dimension Coutry:

               

              <script src="https://rawgit.com/mindspank/qsocks/master/qsocks.bundle.js"></script>
              <script>
              
              
                qsocks.Connect().then(function(global) {
                document.body.innerText = 'Connected'
              
              
                //Open document Sales Discovery
                global.openDoc('QlikSense Intro.qvf').then(function(app) {
              
                global.createDimension('Country').then(function(reply) {
                document.body.innerText = 'Dimension has been created ' + JSON.stringify(reply)
                }, function(error) {
                document.body.innerText = 'Failed to create dimension ' + JSON.stringify(error)
                })
              
              
                }, function(error) {
                document.body.innerText = 'Failed to connect to Application ' + JSON.stringify(error)
              
                })
                }, function(error) {
                document.body.innerText = 'Failed to connect to Qlik Sense Desktop ' + JSON.stringify(error)
              
                })
              
                ;
              
              
              </script>
              <body></body>
              

               

              But it doesn't work this way...

               

              Can you bring me back an track?

               

              Tnx, Halmar