1
votes

Is there anyone worked on HP ALM APIs with PHP?

I am getting the cookies from qcbin/api/authentication/sign-in API

But when I am trying to send these cookies to other subsequent APIs, its returning me httpcode 401 which is not authenticated.

Also i am using the qcbin/authentication-point/authenticate API and qcbin/api/site-session API to get and maintain the sessions.

My code is as follows:

$url = "https://myhost/qcbin/api/authentication/sign-in"; $credentials = $user . ':' . $password; $headers = array("GET /HTTP/1.1","Authorization: Basic ". base64_encode($credentials));

curl_setopt($qc, CURLOPT_URL, $url);
curl_setopt($qc, CURLOPT_HTTPGET,1);
curl_setopt($qc, CURLOPT_HTTPHEADER, $headers);
curl_setopt($qc, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($qc, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($qc);
$response = curl_getinfo($qc);

Then I am trying to get the test set folders:

$folder_name = "folder_name"; $safe_name = rawurlencode($folder_name); $url = "https://myhost/qcbin/rest/domains/NETWORKS_QUALITY/projects/NETWORKS/test-set-folders?query={name['" . $safe_name . "']}";

$qc = curl_init();
curl_setopt($qc, CURLOPT_URL, $url);

//curl_setopt($qc, CURLOPT_HTTPHEADER, $headers);

curl_setopt($qc, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($qc, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($qc, CURLOPT_COOKIE,$ckfile);
curl_setopt($qc, CURLOPT_COOKIEFILE, $ckfile);


curl_setopt($qc, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($qc, CURLOPT_VERBOSE, true);    

$result = curl_exec($qc);
$response = curl_getinfo($qc);

this response returns me httpcode 401 instead of 200. Please help me if anybody worked on this before.

Thank you Biswajit Jena

2

2 Answers

0
votes

trying to understand your query....are you getting back from authentication the 200 success?

I am using REST-API by python module called "requests". If you have a look at the REST API library you should send back the cookie in the header :-) In the automation you should every time look at the header(cookie) and use that to reply it back.

The /HTTP/1.1 in some version of QC ALM is not even needed. In addition in the header you have to specify additional parameter like if you send an xml or a json file format and so on.

Content-Type":"application/xml",
"KeepAlive":"true",
"Authorization":"Basic ",
"QCSession" : None,
"Cookie": None

Please have a look at the QC ALM library, but I hope I have got your point :-) Unfortunately with PHP I cannot help too much, but I cannot see a proper header sent to the server.

0
votes

Yes, I got the solution. Only the required CURL options to be passed to any CURL call.

So I put the following options only and it returned me http_code as 200 and data also. No need to write unnecessary CURL options.

curl_setopt($qc, CURLOPT_URL, $url);
curl_setopt($qc, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($qc, CURLOPT_RETURNTRANSFER, true);

Thank you