1 Reply Latest reply: Aug 23, 2018 3:31 AM by Mathieu Pignon RSS

    Php Qlik ticket request

    ryan cooke

      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?


      //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_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}";
        • Re: Php Qlik ticket request
          Mathieu Pignon

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

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


          public function getQlikTicket($userDirectory, $selectedUser)
                  $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);
                  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'};
                  return $ticket;


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


          Best regards,



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