Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
RedSky001
Partner - Creator III
Partner - Creator III

Newbie using Qlik API JSON

Hi,

I'm trying to learn how to pull data from the Qlik-Sense APi (I'm using just the desktop client, no server).

I've created the WebSocket and a variable myOpenDocObj to hold my OpenDoc Method.

How do I actually send this OpenDoc message to the API and then how do I get back a response ?

 

Any help appreciated (I know this must be very basic stuff for most people on here!)

 

 

<!DOCTYPE html>
<html>
<body>

<h2>This is a test.</h2>

<p id="demo"></p>

<script>
var ws = new WebSocket("ws://localhost:4848/app/");

var myOpenDocObj = 
	{
		"method": "OpenDoc",
		"handle": -1,
		"params": [
			"C:\\Users\\Simon\\Documents\\Qlik\\Sense\\Apps\\Consumer Sales.qvf"
		],
		"outKey": -1,
		"id": 2
	};

	
</script>

</body>
</html>

 

 

Labels (1)
5 Replies
ErikWetterberg

Hi,

ws.send(message) is the method to use. Check the specification here:

https://developer.mozilla.org/en-US/docs/Web/API/WebSocket

To handle the reply you need an eventlistener for the message event. An example is on the same page.

RedSky001
Partner - Creator III
Partner - Creator III
Author

 

Thanks.  I've made some progress now (I'm sending and receiving a response).  However I'm getting an 'invalid request'.

Do you have any idea what I could be doing wrong?

(Thanks again)

Message from server {"jsonrpc":"2.0","method":"OnConnected","params":{"qSessionState":"SESSION_CREATED"}}
(index):37

Message from server {"jsonrpc":"2.0","id":0,"error":{"code":-32600,"parameter":"Request processing error","message":"Invalid Request"}}

<!DOCTYPE html>
<html>
<body>

<h2>This is a test.</h2>

<p id="demo"></p>

<script>

var myOpenDocObj = 
{
	"method": "OpenDoc",
	"handle": -1,
	"params": [
		"C:\\Users\\Simon\\Documents\\Qlik\\Sense\\Apps\\Consumer Sales.qvf"
	],
	"outKey": -1,
	"id": 2
}

// Create WebSocket connection.
const socket = new WebSocket('ws://localhost:4848/app/');

// Connection opened
socket.addEventListener('open', function (event) {
    socket.send(myOpenDocObj);
});

// Listen for messages
socket.addEventListener('message', function (event) {
    console.log('Message from server ', event.data);
});


</script>

</body>
</html>
ErikWetterberg

Hi,

You probably need to include

jsonrpc: "2.0"

and I don't know about the outkey.

RedSky001
Partner - Creator III
Partner - Creator III
Author

Didn't help unfortunately.

I'm now using the exact example Qlik suggest on their webpage:

https://help.qlik.com/en-US/sense-developer/February2019/Subsystems/EngineAPI/Content/Sense_EngineAP...

So I'm passing this JSON string and still getting an 'invalid request' message.

{ "jsonrpc": "2.0", "id": 0 "handle": -1, "method": "GetDocList", "params": [], }

ErikWetterberg

Id should probably not be zero, abd it looks like a comma is missing after
tje zero.