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[i].UserName + ", " + currentCALs[i].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[i].UserName == "FRED")

              currentCALs.Remove(currentCALs[i]);

    }

     

    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.