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.
The Management API is a web service against which you can issue a range of commands to automate management activities on a QlikView environment. There are a couple of prerequisite set up items to do before you can use it and the web service has to be used in a particular way. This document describes how you can configure a Visual Studio project to work with the web service.
An example starter Visual Studio project pre-configured to use the API is attached to this document. The free versions of Visual Studio can be used although some of the screens described below may be slightly different.
Using the API
Step 1 – Set Permissions
To be able to make calls to the management service the request needs to come from a user context with membership of a specific group on the QlikView server. For most API calls the user needs to be a member of the “QlikView Management API” group, this groups is not created by the QlikView installer and so must be created and the relevant users added.
Depending on the type of application you are building you need to use an appropriate way of running the code as a particular user. For example:
- If you have a desktop application, it can run using the login ID of the current user
- If you have a web page then either the user ID of the web site OR the user ID of the person browsing can used
- If you always want a specific user to be used to call commands you can embed this into the code
Further discussion of this subject can be found HERE (TBC)
Step 2 – Create a project & Reference the QlikView Management Web Service
Open Visual Studio and start a new project for the type of solution you want to use. For the example and instructions provided it is a basic console application but the process works the same for asp.net, WinForms etc.
The first step is to connect the QMS API to visual studio by adding a Service Reference
Into the service reference dialogue enter the following URL adjusting for your particular QlikView server address - http://localhost:4799/QMS/Service - click the Go button and it will connect and validate that the service exists. Provide a meaningful name for this reference, for example QMSAPIService. It should look as below
Step 2 – Configure Visual Studio to use a Service Behaviour
The QMS web service requires the presence of a HTTP header containing a “service key” representing your user session with the server. This must be injected into every request and while this is a fairly complex thing to do, QlikView provides the code required to do this in .net projects.
Firstly in Visual Studio create a new folder called ServiceSupport in the root of the projects folder structure.
Download the attached "ServiceSupportFiles.zip" file and extract the 3 files starting with “ServiceKey…cs”. Now right click the folder the folder you created above and click “Add | Existing Item” browse to where you saved the files, select all 3 and click Add. The structure of your project should now look like the below.
Next each of these three files needs to have its namespace edited to match the namespace of your entire project. So open each file and locate the line that will look like this
The namespace of your project will match the name of the project if you didn’t change it and in the above case the text you would change is QMSAPIStarter, leave the ServiceSupport part present
Next open web.config or app.config depending on the type of project you have. Locate the opening tag called <system.serviceModel> and immediately after this paste the below entry
<add name="serviceKeyBehavior" type="QMSAPIStarter.ServiceSupport.ServiceKeyBehaviorExtensionElement, QMSAPIStarter, Version=188.8.131.52, Culture=neutral, PublicKeyToken=null"/>
Notice in the code there are TWO references to the namespace for the code we added above, make sure BOTH of these match the namespace of your project.
Finally locate the following block in the config file
<endpoint address="http://localhost:4799/QMS/Service" binding="basicHttpBinding"
Before the closing tag add behaviorConfiguration="ServiceKeyEndpointBehavior"
Save and close the config file.
Step 3 – Create an object to communicate with the API and add the Service Key
The next step is to write the first piece of code to communicate with the web service, handle the service key and from then on the API functions can be used.
Create the item you want to work with, in this example I am creating a simple class and writing code into the Main method, if you are working with a web page you can locate the code, on load or on the click of a button.
At the top of your code page add the following statements to reference the support functions and the API itself (correct namespace accordingly):
Now into the function you are using paste the below code. This creates the “QMSClient” object from which all subsequent API calls will be made, and packages the service key required to use it. Here i have hard coded the URL to QMS Web Service if you leave it out it will pick up the URL from your config file.
string QMS = "http://localhost:4799/QMS/Service";
Client = new QMSClient("BasicHttpBinding_IQMS", QMS);
string key = Client.GetTimeLimitedServiceKey();
ServiceKeyClientMessageInspector.ServiceKey = key;
The ServiceKey is the token that represents your session with the API. Once the token is obtained it is valid for 20 minutes however this period is extended after each call to the API so you should only need to request a key once.
Step 4 – Issue an API command
Now it is possible to issue commands against the API. Below is a simple function that will ask for the list of services on the QlikView server and print out their names.
ServiceInfo myServices = Client.GetServices(ServiceTypes.All);
foreach (ServiceInfo service in myServices)
Build your project and execute it to see the results. You can now build and run your own applications using the API.
There are a number of objects, types and methods included in the API - Check out the list of examples to see how they can use - see Here