Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Php Qlik ticket request

I've trying to do a php qlik ticket request.

FIrst I had local ssl certificate propblems but then i followed steps to set the windows env var to allow all and then the error went away but with the following all i get is an empty string response.

Any Idea's why?

<?php

//URL of the server

$QRSurl = "https://ip:443/dev-test/";

//Path to call (with xrfkey parameter added)

$xrf      = 'aaaaaaaaaaaaaaaa';

$endpoint = "?xrfkey={$xrf}";

//Location of QRS client certificate

$cert_file = "C:\inetpub\wwwroot\lmc\dependancies\http\login\dependancies\client.pem";

$keyFile   = "C:\inetpub\wwwroot\lmc\dependancies\http\login\dependancies\client_key.pem";

$cert_password = 'dev';

//Set up the required headers

$headers = array(

    'Accept: application/json',

    'Content-Type: application/json',

    'x-qlik-xrfkey: {$xrf}',

    'X-Qlik-User: UserDirectory=UserDir;UserId=client1@example.com'

);

//Create Connection using Curl

$ch = curl_init($QRSurl . $endpoint);

echo $QRSurl . $endpoint . '<br>';

echo '2<br>';

$options = array(

    CURLOPT_SSL_VERIFYPEER => false,

    CURLOPT_HTTPHEADER     => $headers,

    CURLOPT_SSLCERT        => $cert_file,

    CURLOPT_SSLCERTPASSWD  => $cert_password,

    CURLOPT_SSLKEY         => $keyFile,

    CURLOPT_RETURNTRANSFER => true,

    CURLOPT_SSL_VERIFYPEER => false,

    CURLOPT_SSL_VERIFYHOST => false,

    CURLOPT_PROXY          => true

);

curl_setopt_array($ch , $options);

//Execute and print response

echo '3<br>';

$data = curl_exec($ch);

if ($errno = curl_errno($ch))

{

    $error_message = curl_strerror($errno);

    echo "cURL error ({$errno}):\n {$error_message}";

}

var_dump($data);

3 Replies
mathieupignon
Partner - Contributor III
Partner - Contributor III

Here is my working code to request Ticket to Qlik Sense API from PHP server:

getQlikTicket('PITBusiness', 'mathieu.pignon');

public function getQlikTicket($userDirectory, $selectedUser)

    {

        //$targetld=$_GET["targetld"];

        //$proxyRestUri=$_GET["proxyRestUri"];

        $proxyRestUri = 'https://myqliksense-url.com:4243/qps';

        $reqFields = array('UserDirectory' => $userDirectory, 'UserId' => $selectedUser, 'Attributes' => array());//, 'Targetld' => $targetld);

        $url = $proxyRestUri . '/ticket?xrfkey=ABCDEFG123456789';

        //$certFile = "/var/www/spoom-demo1/ba_bpm/web/client.pem";

        //$keyFile   = "/var/www/spoom-demo1/ba_bpm/web/client_key.pem";

        $certFile = "/home/docker/web/localhost.pem";

        $keyFile   = "/home/docker/web/localhost_key.pem";

        $certPassword = 'secret';

        $request = curl_init();

        $options = array(

          CURLOPT_URL => $url,

          CURLOPT_SSLCERT => $certFile,

          CURLOPT_SSLCERTPASSWD => $certPassword,

          CURLOPT_SSLKEY => $keyFile,

          CURLOPT_RETURNTRANSFER => true,

          CURLOPT_FOLLOWLOCATION => true,

          CURLOPT_SSL_VERIFYHOST => false,

          CURLOPT_SSL_VERIFYPEER => false,

          CURLOPT_HTTPHEADER => array('X-Qlik-Xrfkey:ABCDEFG123456789', 'Content-Type: application/json'),

          CURLOPT_POSTFIELDS => json_encode($reqFields),

        );

        curl_setopt($request, CURLOPT_CUSTOMREQUEST, "POST");

        curl_setopt_array($request, $options);

        $response = curl_exec($request);

        //print_r($response);

        if (!$response) {

            if ($errno = curl_errno($request)) {

                $errorMessage = curl_strerror($errno);

                echo "cURL error ({$errno}):\n {$errorMessage}";

            }

            echo "\r\n\r\n";

            foreach ($options as $key => $value) {

                echo "$key = $value\r\n";

            }

            echo "\r\n\r\n";

        } else {

            $decodedJSON = json_decode($response);

            $ticket = $decodedJSON->{'Ticket'};

        }

        curl_close($request);

        return $ticket;

    }

First big difference I see with your code is with the URL.

Best regards,

Mathieu

Visit www.pit-business.com to get nice Qlik Sense tools and advises from the best Qlik Influence Partner in Benelux.

Mathias
Partner - Contributor II
Partner - Contributor II

Does it still work? I am trying to setup a simple login webpage but it doesn't work

mathieupignon
Partner - Contributor III
Partner - Contributor III

It uses to work a month ago on Qlik Sense November 2017.

It's no more working in our application, but I guess it's a problem with SSL, cross-domain or certificates.