Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
QIX API looks like very useful tool. However, I am not able to keep the connection open. Below is the code I attempted in another server different to Qlik Sense server.
Command Prompt:
wscat -c ws://qliksense/app/<app id>
Connected (press CTRL+C to quit)
< {"jsonrpc":"2.0","method":"OnAuthenticationInformation","params":{"loginUri":"http://qliksense:80/internal_forms_authentication/?targetId=d1ea041a-1f26-454d-82a7-05021899b818","mustAuthenticate":true}}
Disconnected (code: 1001, reason: "")
As you can see above immediately after "connected", it gets "Disconnected" without me entering any details.
Don't know what is the problem. Am I missing some headers or authentication? Is there an example that I could refer too?. Any guidance will be helpful. Thank you
Is this the wscat you are referring to: https://github.com/websockets/wscat?
Half the answer may be to use wscat's --header "Cookie:X-Qlik-Session-HTTP=xxxxx-xxx-xxx...".
The missing half, is how to get the session cookie.
Try it manually first, using the session cookie you see in either each request, or under DevTools - Applications - Cookies - <Your host name>.
I don't know wscat. But from the look of things, it only supports basic authentication ('--auth'). But I don't think Qlik supports Basic authentication, at least not on the webscoket call. (Correct me if I'm wrong, anyone.)
So in that case, you need to do another normal GET request first, to obtain a session, and a session cookie. (For example https://<server>/<v.proxy>/api/about/v1/systemInfo, which will redirect you to a login module.) But it is likely that it will need human interaction to log in.
If that is not good enough, you might have to go down the certificates path. If so, I would recommend running this from the same server as Qlik is running on.
Vegard 🙂
You're not authenticated ("mustAuthenticate": true). That's why you get disconnected. You need to authenticate according to the authentication method of the virtual proxy you are connecting to.
Hi @Øystein_Kolsrud , Thank you for your solution. I tried using below syntax with my normal browser login details but doesn't seem to work. May be I have to use an API key? I will try to figure this out. Please let me know if I am going in the wrong way. An example would be very helpful. Thank you 🙂
--auth <username:password>
I'm not familiar with wscat, so can't give much help on that part, but in general (as you are already exploring) the authentication flow requires you to set the correct headers. Which headers to set depend totally on the authentication method used by the virtual proxy you are connecting to, so in order to help you further you'll need to provide information about the nature of that virtual proxy. And it's also important to know if you are trying to connect to the SaaS or the Windows edition.
Getting that authentication right can be quite complicated, but there are a number of libraries available that makes it easier for you. And especially if you want to authenticate using Windows credentials, then it is highly recommended that you perform your websocket interaction through either JavaScript or .NET. For .NET you can find examples on how to do different types of authentication here:
You could also try qlik-cli for connecting to your server: https://qlik.dev/libraries-and-tools/qlik-cli
If you are using ws://qliksense/app/<app id>, you might be using the default virtual proxy, with default authentication.
How do you log in when you contact: http://qliksense/hub/? If you get straight in, you might have single-sign-on using NTLM.
What headers are set for the websocket request from your browser's Network, under DevTools (F12)?
If you set the session cookie, you might be alright.
@vegard_bakkethnak you for your reply. When I login using browser, I had to enter my windows authentication details. And below are the ws get request detail
GET ws://domain/hub/qrsData?reloadUri=htt..
Request Headers:
Cookie: X-Qlik-Session-HTTP=xxxxx-xxx-xxx...
Sec-WebSocket-Key: xyz...
Upgrade: websocket
Is this the wscat you are referring to: https://github.com/websockets/wscat?
Half the answer may be to use wscat's --header "Cookie:X-Qlik-Session-HTTP=xxxxx-xxx-xxx...".
The missing half, is how to get the session cookie.
Try it manually first, using the session cookie you see in either each request, or under DevTools - Applications - Cookies - <Your host name>.
I don't know wscat. But from the look of things, it only supports basic authentication ('--auth'). But I don't think Qlik supports Basic authentication, at least not on the webscoket call. (Correct me if I'm wrong, anyone.)
So in that case, you need to do another normal GET request first, to obtain a session, and a session cookie. (For example https://<server>/<v.proxy>/api/about/v1/systemInfo, which will redirect you to a login module.) But it is likely that it will need human interaction to log in.
If that is not good enough, you might have to go down the certificates path. If so, I would recommend running this from the same server as Qlik is running on.
Vegard 🙂
@vegard_bakke As you said I used the session cookie from the browser and it worked straightway Thank you so much for your helpful. And yes I was referring (wscat) to the link that you mentioned in your response.
For anyone looking to give it a try here is the syntax that worked for me,
wscat -c ws://<Qlik server>/app/<app id> --header "Cookie:X-Qlik-Session-HTTP=<copy paste from web browser - dev tools -- ws - request headers>"