Qlik Community

QlikView Management

Discussion Board for collaboration on QlikView Management.

Not applicable

QlikView management API and PHP

Okay so I have been scratching my head for a while on this problem and would appreciate any help / guidance I can get.  So this is the problem:  Basically QlikView server management 11 release API in the method of SOAP.  So what I am trying to do is to write a simple php script(to learn!) that uses one of the SOAP operation.  I am trying to get the limited service key by using the GetTimeLimitedServiceKey, but unfortunately, when I run my script I get the following error: "Unauthorized".  Has anyone been able to write a simple script in PHP that uses the management API?

This is my simple code below:

//----------------------------------------------------------------------------------------------------------------

<?php

    try {

            $options = array(

                'soap_version'=>SOAP_1_1,

                'exceptions'=>true,

                'trace'=>1,

                'cache_wsdl'=>WSDL_CACHE_NONE,

                'login'=>"username",

                'password'=> "*******"

            );

            $client = new SoapClient('http://qlikviewserver:4799/QMS/Service?WSDL', $options);

// Note where 'Get' and 'request' tags are in the XML

            $results = $client->GetTimeLimitedServiceKey();

         } catch (Exception $e) {

            echo "<h2>Exception Error!</h2>";

            echo $e->getMessage();

        }

$results = $client->GetTimeLimitedServiceKey();

?>

Thanks.

Tags (2)
1 Solution

Accepted Solutions
Not applicable

Re: QlikView management API and PHP

Hi Samuel,

Yes, I use PHP to manage my Qlikview 10 server.

Your piece of code doesn't work because Qlikview uses the NTLM protocol.

You need to redefine the __doRequest() method like above :

class NTLMSoapClient extends SoapClient

{

     public $serviceKey = null;

     function __doRequest($request, $location, $action, $version, $one_way = 0)

     {

          $headers = array(

               'Method: POST',

               'Connection: Keep-Alive',

               'User-Agent: PHP-SOAP-CURL',

               'Content-Type: text/xml; charset=utf-8;',

               'SOAPAction: '.$action

          );

          //Once you have a service key

          if ($this->serviceKey)

               $headers[] = 'X-Service-Key: ' . $this->serviceKey;

          $this->__last_request_headers = $headers;

          $ch = curl_init($location);

          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

          curl_setopt($ch, CURLOPT_POST, true);

          curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

          curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

          curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);

          curl_setopt($ch, CURLOPT_USERPWD, 'USERSmiley TongueASSWORD');

          $response = curl_exec($ch);

          return $response;

     }

     function __getLastRequestHeaders() {

          return implode("\n", $this->__last_request_headers)."\n";

     }

}

You will have to edit the 'USERSmiley TongueASSWORD' with yours, the user has to be in "Qlikview Administrators" AND "Qlikview Management API" group

And a piece of code to use it :

$options = array(

     'exceptions'=>true,

     'trace'=>1

);

//Create SOAP connexion

$client = new NTLMSoapClient('http://localhost:4799/QMS', $options);

//Retrieve a time limited service key

$client->serviceKey = $client->GetTimeLimitedServiceKey()->GetTimeLimitedServiceKeyResult;

//Retrieve server info

$qlikviewServerInfo = $client->GetServices(array('serviceTypes' => 'QlikViewServer'))->GetServicesResult;

echo 'QVS ID: ' . $qlikviewServerInfo->ServiceInfo->ID;

I hope it will help ! The technical documentation is the worst I've ever seen !!

10 Replies
Not applicable

Re: QlikView management API and PHP

Hi Samuel,

Yes, I use PHP to manage my Qlikview 10 server.

Your piece of code doesn't work because Qlikview uses the NTLM protocol.

You need to redefine the __doRequest() method like above :

class NTLMSoapClient extends SoapClient

{

     public $serviceKey = null;

     function __doRequest($request, $location, $action, $version, $one_way = 0)

     {

          $headers = array(

               'Method: POST',

               'Connection: Keep-Alive',

               'User-Agent: PHP-SOAP-CURL',

               'Content-Type: text/xml; charset=utf-8;',

               'SOAPAction: '.$action

          );

          //Once you have a service key

          if ($this->serviceKey)

               $headers[] = 'X-Service-Key: ' . $this->serviceKey;

          $this->__last_request_headers = $headers;

          $ch = curl_init($location);

          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

          curl_setopt($ch, CURLOPT_POST, true);

          curl_setopt($ch, CURLOPT_POSTFIELDS, $request);

          curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

          curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);

          curl_setopt($ch, CURLOPT_USERPWD, 'USERSmiley TongueASSWORD');

          $response = curl_exec($ch);

          return $response;

     }

     function __getLastRequestHeaders() {

          return implode("\n", $this->__last_request_headers)."\n";

     }

}

You will have to edit the 'USERSmiley TongueASSWORD' with yours, the user has to be in "Qlikview Administrators" AND "Qlikview Management API" group

And a piece of code to use it :

$options = array(

     'exceptions'=>true,

     'trace'=>1

);

//Create SOAP connexion

$client = new NTLMSoapClient('http://localhost:4799/QMS', $options);

//Retrieve a time limited service key

$client->serviceKey = $client->GetTimeLimitedServiceKey()->GetTimeLimitedServiceKeyResult;

//Retrieve server info

$qlikviewServerInfo = $client->GetServices(array('serviceTypes' => 'QlikViewServer'))->GetServicesResult;

echo 'QVS ID: ' . $qlikviewServerInfo->ServiceInfo->ID;

I hope it will help ! The technical documentation is the worst I've ever seen !!

Not applicable

QlikView management API and PHP

Hey David,

      Thank you so much for this.  I have gotten so far in almost getting it to work.  You are right that technical documentation is horrible.  Anyway, I did have one last issue when I tried running your code, When I run the following:

//Retrieve a time limited service key

$client->serviceKey = $client->GetTimeLimitedServiceKey()->GetTimeLimitedServiceKeyResult;

I catch an exception: Caught exception: SoapClient::__doRequest() returned non string value

Was wondering if you had a similar issue and if so, any direction on trying to fix it would be great!

Again thanks for you help!

Sam

Not applicable

Re: QlikView management API and PHP

Hey David

   Figured out the issue! of the Caught exception: SoapClient::__doRequest() returned non string value.  The PHP version 5.3.4 that I was running had a bug in Curl that was giving that error message above.  The fix was upgrading PHP to version 5.3.9 and it worked.  Again thanks for all your help!

Thanks again.

Sam.   

Not applicable

Re: QlikView management API and PHP

You're welcome !

perumal_41
Valued Contributor II

Re: QlikView management API and PHP

Hi,

i want Develop  Qlikview Management API in PHP,i don't know how Develop,

Please Guide Me .,If possible Send Sample PHP Code for Qlikview management API developement

Not applicable

Re: QlikView management API and PHP

Is it a joke ?

There is a sample, 3 post above...

Not applicable

QlikView management API and PHP

Hi David,

I'm trying to utilize the web service of QV11 but don't have success doing it.

Eclipse is complaining that it cannot retrieve the wsdl file but when I access it in IE the wsdl file show up.

I'm using this to access the webservice http://localhost:4799/QMS/Service .

I'm just thinking that maybe you know also how to call the Web service in Java.

Any response is highly appreciated.


Thanks a lot.

Not applicable

Re: QlikView management API and PHP

Hi davidbertet

Seems you might be the only person who knows how to do this online. Haha!

After you have your service key, what does it look like for your next api calls? Like if i was following QlikView Management API - #2 Export / Add / Delete Document CALs and I wanted to get all the docs from the GetUserDocuments() action.

Not applicable

Re: QlikView management API and PHP

Hi Blake,

Sadly I don't use QlikView anymore, so I'll don't be very useful.

What's your problem precisely ? Once you have initialized your $client, you can call everything on it like in the example : $client->GetUserDocuments(...)

Community Browser