Skip to main content
Announcements
Qlik Community Office Hours, March 20th. Former Talend Community users, ask your questions live. SIGN UP
cancel
Showing results for 
Search instead for 
Did you mean: 
berndpodhradsky
Partner - Contributor III
Partner - Contributor III

.NET SDK with Qlik Sense Business

Hi everyone!

Currently the .NET SDK does not support to connect to a Qlik Sense Business instance. Are there any plans to include that functionality in the near future? Or what are alternative solutions?

Kind Regards,
Bernd

Labels (2)
16 Replies
Øystein_Kolsrud
Employee
Employee

You should be able to use JWT authentication if you can produce an API key. The endpoint to use is "location.AsJwtViaProxy", and though it's originally intended to use with an on-site Enterprise proxy, it works with cloud as well. I've never tried with Qlik Sense Business though, so there might be some special configurations involved to enable that type of authentication, but this is what it look like when I connect to QCS:

 

// Get appId using rest client.
var restClient = new RestClient(url);
restClient.AsJwtViaQcs(token);
var appInfo = restClient.Get<JObject>("/api/v1/items?resourceType=app&name=" + appName)["data"].First();
var appId = new AppIdentifier {AppId = appInfo["resourceId"].Value<string>()};

// Get properties of the app.
var location = Location.FromUri(url);
location.AsJwtViaProxy(token);
using (var app = location.App(appId))
{
    Console.WriteLine(app.GetAppProperties().ToString());
}

 

A difference from when connecting to Qlik Sense Enterprise is that you must use a session with a valid appId when connecting. So just doing "location.Hub()" won't work. In the example above I'm using Newtonsoft for JSON handling and the following library for REST access:

https://www.nuget.org/packages/QlikSenseRestClient/

Øystein_Kolsrud
Employee
Employee

And the specification for that REST endpoint I use can be found here: https://qlik.dev/apis/rest/items

berndpodhradsky
Partner - Contributor III
Partner - Contributor III
Author

Hi!

Thanks a lot, that did the trick. The only thing we haven't managed to get working.

In on-premise Qlik Sense installations we create a custom session, perform some filtering with API Calls and then embed a visualization into a webpage using the &identity parameter which holds the ID of the custom session that we have created; thus, the API calls and the embedded visualization share a single custom session and API calls in the background affect the visualization.

With Qlik Sense Business however, it seems to ignore the &identity parameter. Any hint you can give me as to why that would be the case? Or anything else to consider?

Thanks,
Bernd

Øystein_Kolsrud
Employee
Employee

I'm afraid I'm not familiar with how that session identification works in the cloud product, so can't help you there.

berndpodhradsky
Partner - Contributor III
Partner - Contributor III
Author

Hi!

Thanks! Any idea who I can turn to in order to get more information about that?

Bernd

Øystein_Kolsrud
Employee
Employee

Looks like I figured it out! The trick is to explicitly set the "SessionToken" property of the "Session" object used when connecting. If you set this to the empty string, then you'll connect to the same session as what you get when you connect with the client. So like this:

var location = Location.FromUri(url);
location.AsJwtViaProxy(token);
var session = Session.WithApp(appId);
session.SessionToken = "";
using (var app = location.App(appId, session))
{
    Console.WriteLine(app.Evaluate("=Count(distinct Dim1)"));
}

The number that code prints will depend on the selection state of the client. If you want to connect to a different session, then you can set a different value for "SessionToken", like this:

var session = Session.WithApp(appId);
session.SessionToken = "MyToken";

If you don't set "SessionToken" or use the "sessionToken" argument of the "WithApp" method, then you'll get a configuration that is designed for the needs of QSEfW (including that "identity" part that you mentioned). The needs for QCS is different here, and explicitly setting that "SessionToken" property will override the default behavior.

berndpodhradsky
Partner - Contributor III
Partner - Contributor III
Author

Hi!

Thanks. Tried it out, but unfortunately didn't work. It sets the filters within the session, that's correct. But the chart (even though I use the "&identity" query string parameter) still displays an unfiltered set of values.

Bernd

Øystein_Kolsrud
Employee
Employee

Don't use the "&identity" query string parameter. It won't work in QCS. You need to set the header X-Qlik-Session when you connect. It is into that header that the "SessionToken" value goes. The QCS client doesn't set that header by default, so omitting that header or setting it to the empty string gives you the same session as the client per default connects to. If you set that header in the browser to any other value, and use the same value in the "SessionToken" property as described above, then both will connect to the same session which is independent of the one you get if you don't use the header.

berndpodhradsky
Partner - Contributor III
Partner - Contributor III
Author

Hi!

Hm... something's not quite working as expected. Let me wrap it up. Here's what I do:

 

_location = Location.FromUri(....)
Location.AsJwtViaProxy(...)

_session = Session.withApp(appId)
_session.SessionToken = "a random GUID"

_app = _location.App(appId, _session)

Interestingly, at this point the _location object has a custom header property with an X-Qlik-Session already set (but different from my randomly generated GUID). I suspect that this is the default session.

Then I perform some filters on the _app and after that I set the X-Qlik-Session cookie of a browser to the random GUID I previously created and open a single URL (without the identity query string). However, the object still displays as if nothing was filtered. If I remove all the custom session token stuff, the object displays correctly, but of course the session is then the shared one, which wouldn't work in our scenario.

I even tried to set the "X-Qlik-Session" header of the _location object to the randomly created GUID but that doesn't change anything.

Not sure where exactly I'm going the wrong way, but can you confirm that in your solution you can actually view a visualization using that method which displays correctly within a custom session?

Thanks for your help!

Bernd