1

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

Biswajit
  • 81
  • 1
  • 2

2 Answers2

0

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.

Marco smdm
  • 1,020
  • 1
  • 15
  • 25
  • Thank you Marco. Yes I am getting 200 from authentication API. As per your comment I need to send the cookie in header. I have tried to send the cookie in header also but did not worked. – Biswajit Jun 13 '17 at 10:37
  • In python for instance my requests looks like: mySession.get(url, data=xml_data, header=my_header) . Most probably I guess in your case you should check how to send the header by the usage of curl action. – Marco smdm Jun 13 '17 at 11:03
  • During authentication process since this is the first message you are not using any important header ;) then the LSSO-Cookie has to be used. – Marco smdm Jun 13 '17 at 11:04
0

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

Biswajit
  • 81
  • 1
  • 2
  • Very good indeed :-) You have then always to use the cookie option to get into next query and so on! Have a nice day and please close the question ;) – Marco smdm Jun 14 '17 at 07:53