Highlighted
Established Member..
Established Member..
4232 views

HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

Hi,

   I am working with HP Performance Center 12. In my project, I need to get information related to runs by executing some Java APIs which internally call the REST methods and read the output XMLs.

  Till HP Performance Center 11.5, this worked seamlessly. But with HP PC 12, things have changed. Now the Java API returns the following error when accesing the REST URLs:

Error 401 Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access.

 

 

Can anyone advise how to bypass this authentication layer so that my project can function seamlessly, without any user intervention, as before?

 

Appreciate the help.

0 Likes
1 Solution

Accepted Solutions
Highlighted
Established Member..
Established Member..

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

OK, so I found the solution to this. It was simpler than I thought, but lack of examples contributed to the confusion I think.

 

So, there is a subtle difference in accessing information with the ALM REST API version 12 as compared to 11.5

 

First step: Authentication (same as HP PC 11.5)

AuthenticateLoginLogoutExample login = new AuthenticateLoginLogoutExample();
login.login(Constants.USERNAME, Constants.PASSWORD);

 

Second step: Get the rest-session (new in HP PC 12)

Map<String, String> requestHeaders = new HashMap<String, String>();
String qcsession = con.buildUrl("rest/site-session");
con.httpPost(qcsession, null, requestHeaders);

 

Third step: Post your actual request

String finalUri = new String("rest/domains/DEFAULT/projects/MyProject/runs/?fields=id&query={pc-reservation-id[=43246]}");

String resourceWeWantToRead = con.buildUrl(finalUri);
byte[] response = con.httpGet(resourceWeWantToRead, null, requestHeaders).getResponseData();

 

 

I was manually passing the required cookies - QCSessionID, JSESSIONID, LWSSO_COOKIE_KEY etc. as seen in my code in a previous comment. This is not required.

 

Hope this helps.

 

 

View solution in original post

0 Likes
6 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

Are you referring to ALM or PC REST API?

For PC the REST API is available starting PC12 only.

0 Likes
Highlighted
Established Member..
Established Member..

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

Thanks for your response Madan, yes I am using PC12.

0 Likes
Highlighted
Established Member..
Established Member..

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

I did the following:

 

1. Tried using the API document example code in 'AuthenticateLoginLogout Example' to authenticate the user.

 

2. Then I do an httpPost for the url "rest/site-session" to get the QCSession, JSESSIONID, LWSSO_COOKIE_KEY etc.

 

3. After that I add the values got above in the request header under Cookie:

 

requestHeaders.put("Cookie", "[LWSSO_COOKIE_KEY=" + this.LWSSO_COOKIE_KEY +
";Path=/, JSESSIONID=" + this.JSessionID +
";Path=/, X-XSRF-TOKEN=" + this.XSRFTOKEN +
";Path=/, ALM_USER=" + this.ALM_USER +
";Path=/, QCSession={" + this.cookieQCSession + ";Path=/]" );

 

4. With these fresh headers in place I do an httpPost with a new URL - "rest/domains/DEFAULT/projects/MYPROJ/runs/?fields=id&query={pc-reservation-id[=1234]}"

 

But even after passing the QCSession etc, I still get 401.

 

I am not understanding why the user is not being recognized in the second call inspite of passing all the details in the Cookie.

 

Kindly advise.

0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

It is not PC API, You  are using ALM REST API. I request to post it in the ALM/QC forum for getting better help.

 

0 Likes
Highlighted
Established Member..
Established Member..

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution
Highlighted
Established Member..
Established Member..

Re: HP Performance Center 12 - Rest API - Bypassing Error 401 related to login-form-required=y

Jump to solution

OK, so I found the solution to this. It was simpler than I thought, but lack of examples contributed to the confusion I think.

 

So, there is a subtle difference in accessing information with the ALM REST API version 12 as compared to 11.5

 

First step: Authentication (same as HP PC 11.5)

AuthenticateLoginLogoutExample login = new AuthenticateLoginLogoutExample();
login.login(Constants.USERNAME, Constants.PASSWORD);

 

Second step: Get the rest-session (new in HP PC 12)

Map<String, String> requestHeaders = new HashMap<String, String>();
String qcsession = con.buildUrl("rest/site-session");
con.httpPost(qcsession, null, requestHeaders);

 

Third step: Post your actual request

String finalUri = new String("rest/domains/DEFAULT/projects/MyProject/runs/?fields=id&query={pc-reservation-id[=43246]}");

String resourceWeWantToRead = con.buildUrl(finalUri);
byte[] response = con.httpGet(resourceWeWantToRead, null, requestHeaders).getResponseData();

 

 

I was manually passing the required cookies - QCSessionID, JSESSIONID, LWSSO_COOKIE_KEY etc. as seen in my code in a previous comment. This is not required.

 

Hope this helps.

 

 

View solution in original post

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.