Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikhalmar
Creator
Creator

Start with Qlik Engine API

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

1 Solution

Accepted Solutions
Alexander_Thor
Employee
Employee

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/Glo...

  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>

View solution in original post

3 Replies
Alexander_Thor
Employee
Employee

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/Glo...

  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>

qlikhalmar
Creator
Creator
Author

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

Alexander_Thor
Employee
Employee

Hey,

You can find the documentation for CreateDimension here, https://help.qlik.com/sense/2.0/en-us/developer/Subsystems/EngineAPI/Content/Classes/AppClass/App-cl...

You'll notice that createDimension is a method on the App class so it's not something you can invoke from the global class. So when you call global.openDoc() it will return a handle to the app that was opened, this corresponds to the app class. Similarly when you call app.createDimension() it will return a handle/class to that genericDimension so you can invoke methods against the dimension if you would like.

I put up a gist here that shows how you create a dimension createdimension.js · GitHub it uses node but the same code would work in the browser just remove the require part of course

In that sample you will notice that I set a few properties that are not prefixed with q, these are dynamic properties that our engine does not care about but our client uses to render the information from the engine.