Qlik Community

QlikView Documents

Documents for QlikView related information.

QlikView Management API - #3 Export / Add / Delete Named CALs

jbc
New Contributor III

QlikView Management API - #3 Export / Add / Delete Named CALs

Introduction

This document is part of a series of documents that discuss how to use the QlikView Management API. You can find the index for these documents Here.

Please review the getting started document before continuing.

In this example we will review ways that the API can be used to work with Named CALs with a couple of examples attached.

Note - Under the terms of the QlikView Licence Agreement, Named CALs are intended to be persistant for a user  i.e. they should not be shared or deleted unless that user leaves an organisation or role.

Working with Named CALs

Named CALs are allocated user and stored in .pgo files on the QlikView sever.  Using the API this data can be consumed and edited to export/add/delete Named CALs.  In these examples we will mainly be working with the AssignedNamedCAL object.

First off all you need to connect to the management API and handle the Service Key process:

QMSClient Client;

string QMS = "http://localhost:4799/QMS/Service";

Client = new QMSClient("BasicHttpBinding_IQMS", QMS);

string key = Client.GetTimeLimitedServiceKey();

ServiceKeyClientMessageInspector.ServiceKey = key;

Exporting Named CAL Data

To begin we need to reference the QlikView server we want to connect to so we can read its settings.  ServiceInfo is an array of all the services of a given type, so if you had more than one QV Server you would need to use the right one, for now we will assume its just one.

ServiceInfo[] MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);

Next we can obtain the CALConfiguration object from the server and from within that the AssignedNamedCALs

CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);

List<AssignedNamedCAL> currentCALs = myCALs.NamedCALs.AssignedCALs.ToList();

Now we have this array we can loop through it to display the data in the list, this can be modified to export the data to a file


for (int i=0;i<currentCALs.Count;i++)

{

Console.WriteLine(currentCALs.UserName + ", " + currentCALs.LastUsed);

}

Adding a Named CAL

In this example we can work with the same CALConfiguration object to add a new CAL entry for a user.

Start the same way as above getting the details of the server and the current CALConfiguration and AssignedNamedCAL objects

ServiceInfo[] MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);

CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);

List<AssignedNamedCAL> currentCALs = myCALs.NamedCALs.AssignedCALs.ToList();

Next we create a new AssignedNamedCAL object and provide the user name

AssignedNamedCAL newCAL = new AssignedNamedCAL();

newCAL.UserName = "Fred";

Add the new CAL to the existing list of CALs and then add the list back into the CAL configuration

currentCALs.Add(newCAL);

myCALs.NamedCALs.AssignedCALs = currentCALs.ToArray();

Finally save the new CAL Configuration to the server

Client.SaveCALConfiguration(myCALs);

Deleting a Named CAL

Deleting a CAL is similar to adding one only we have to find the right entry first

Start the same way as above getting the details of the server and the current CALConfiguration and AssignedNamedCAL objects

ServiceInfo[] MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);

CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);

List<AssignedNamedCAL> currentCALs = myCALs.NamedCALs.AssignedCALs.ToList();

Next we loop through the list of Assigned CALs looking for the user you want to remove, note that the UserName string coming back is in Upper Case.

for (int i = 0; i < currentCALs.Count; i++)

{

     if(currentCALs.UserName == "FRED")

          currentCALs.Remove(currentCALs);

}

Now the modifued list of CALs is added back into the CAL configuration

myCALs.NamedCALs.AssignedCALs = currentCALs.ToArray();

Finally save the new CAL Configuration to the server

Client.SaveCALConfiguration(myCALs);

Other items

The CALConfiguration object contains all of the settings associated with server wide licences, that is Named, Session and Usage CALs.  You can view a lot more information by browsing through the various properties of this object.

Labels (3)
Attachments
Comments
Not applicable

Using QMSAPI v11 R2 I had to drop the "ToArray()" to get the code above to compile in VS 2010.

myCALs.NamedCALs.AssignedCALs = currentCALs.ToArray();

Not applicable

We have limited user cal license to access the QlikView, hence we created a program which automatically removes or frees inactive user who did not access for over 24 hours quarantined period.

The program designed to removing the user who's "LastUsed" time period is over 24 hours, however on some instance its not deleting the user rather its flagging/marking the user for delete. This prevents user from accessing the report for additional 24 hours from the time its marked.

I originally thought may be we has problem calculating the "LastUsed" date value, so I created log, to report the time before deleting. The user which are being flagged has well over 24 hrs reported as "LastUsed" in log, yet its not deleting the user rather marking for delete. Not sure what we are missing, I would appreciate any sort of help to address this issue

Not applicable

Does anyone know how to assign users to document calcs and license then? or is there any examples?

kanhomcake
New Contributor III

Try this.....shamiullahms it works for me so far...

static void ReleaseQuarantinedCAL()
        {
            QMSClient Client;
            string QMS = ConfigurationManager.AppSettings["QVServer"];
            Client = new QMSClient("BasicHttpBinding_IQMS", QMS);
            string key = Client.GetTimeLimitedServiceKey();
            ServiceKeyClientMessageInspector.ServiceKey = key;

            ServiceInfo[] MyQVS = Client.GetServices(ServiceTypes.QlikViewServer);

            CALConfiguration myCALs = Client.GetCALConfiguration(MyQVS[0].ID, CALConfigurationScope.NamedCALs);

            List<AssignedNamedCAL> currentCALs = myCALs.NamedCALs.AssignedCALs.ToList();

            int intCALs = currentCALs.Count;

            for (int i = 0; i < intCALs; i++)
            {
                if (currentCALs.QuarantinedUntil.Year > 1)
                {
                    currentCALs.QuarantinedUntil = new DateTime(1, 1, 1);
                }
            }
           
            myCALs.NamedCALs.AssignedCALs = currentCALs.ToArray();
            Client.SaveCALConfiguration(myCALs);
           
        }

jasonseril
Contributor

In the QMC, System->Licenses-Client Access Licenses (CALs)  tab, we can limit the number of CALs use. My inquiry is it possible to control the settings using the QMS API?  are there any examples about this requirements? 

thank you in advance.

diethardt
New Contributor

Hello, I'm using the programm for deleting named CAL's. We are removing all CALS from the last day. Each time the remove command is executed, the entry is removed from the CAL list. So if we increment the counter i++ the system skips one license. So we used i-- in the loop to correct the counter.

if (currentCALs.LastUsed.Day < Tag)

     {

            currentCALs.Remove(currentCALs);

     i--;

     }


Thanks a lot for the good examples.

karthikeyan1504
Contributor III

Hi,

When I try to run the QMS API Named CALs, I am getting an error as 'Invalid license data. Reinstall is required' from Visual Studio 2010 Shell.

Someone please advise me to fix this issue.

Thanks & Regards,

Karthikeyan.

sohailansari201
Contributor

I have created an app using the QMS API code to remove the DOC CALs. It executes without any error (I can successfully step onto each line of code and confirm no error). But it doesn't remove the DOC license from the document? Here is a piece of code that removes the license. Can somebody notice anything wrong here? Thank you,

screenshot.png

martinpedersen
Contributor

I got the same issue. It looks like the solution isn't supported in Qlikview 12+?

The add or remove qaurantined user works, but the Remove doesn't respond. I have tried to find some updated API descriptions for version 12, but so far no luck.

gballester
New Contributor III

hello Martin, I have a same problem.

i tried to use the reloaded service of QlikView 12, and the GetServices(ServiceTypes.QlikViewServer) method fails.

in this url exits the API reference information

https://help.qlik.com/en-US/qlikview-developer/12.1/apis/QMS%20API/html/7b30b3a1-77da-4bbe-bdc2-1320...

but, i don´t want the solution for my problem. In QlikView 11 work ok, but in QlikView 12 i have a lot of problems.

Version history
Revision #:
1 of 1
Last update:
‎11-21-2012 11:09 AM
Updated by:
jbc