Connecting with PHP

PHP is a web application technology. From within PHP, the cURL function can be used to interact with web services as described below. If Microsoft Windows authentication is used, see Connecting with cURL.

The following example shows how to use PHP to connect to the Qlik Sense Repository Service (QRS) API and retrieve a list of apps in JSON format.

In the example, certificates are used for authentication and they must be in PEM format. The certificates can be obtained by exporting them from the Qlik Management Console (QMC) in PEM format including the secret key.

When using a certificate to authenticate, requests are made with full administrator rights. To run the commands as a specific user, add the X-Qlik-User header to use the security context of that user account.

<?php //URL of the server $QRSurl = "https://localhost:4242/qrs"; //Path to call (with xrfkey parameter added) $endpoint = "/app?xrfkey=0123456789abcdef"; //Location of QRS client certificate and certificate key, assuming key is included separately $QRSCertfile = "C:\PHPapps\client.pem"; $QRSCertkeyfile = "C:\PHPapps\client_key.pem"; //Set up the required headers $headers = array( 'Accept: application/json', 'Content-Type: application/json', 'x-qlik-xrfkey: 0123456789abcdef', 'X-Qlik-User: UserDirectory=Internal;UserId=sa_repository' ); //Create Connection using Curl $ch = curl_init($QRSurl . $endpoint); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSLCERT, $QRSCertfile); curl_setopt($ch, CURLOPT_SSLKEY, $QRSCertkeyfile); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //Execute and print response $data = curl_exec($ch); echo $data; ?>

Did this information help you?

Thanks for letting us know. Is there anything you'd like to tell us about this topic?

Can you tell us why it did not help you and how we can improve it?