Highlighted
Trusted Contributor.
Trusted Contributor.
1022 views

Rest API to run a test using powershell

Jump to solution

Hi,

I am using Performance Centre 12.55 and have a requirement to execute test from octopus (CI).

I have added a powershell script and was able to authenticate successfully. But when I try to execute the PUT call for running the test, I am always getting the error "Operation failed 1001".

I tried using Postman with the same cookies and the test is executed successfully.

Please find below my script for your reference:

$Get_Url = 'http://xxx/LoadTest/rest/authentication-point/authenticate/'
$username='xxx'
$password='xxx'
$AuthKey = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

Invoke-RestMethod -Method Get -Uri $Get_Url -Headers @{Authorization = "Basic $AuthKey" } -SessionVariable websession

 

$Put_Url = 'http://webqapc/LoadTest/rest/domains/ASB_TEST/projects/Digital_MovingMoney/runs'
$content_type = 'application/xml'
$Body = '
<Run xmlns="http://www.hp.com/PC/REST/API">
<PostRunAction>Collate And Analyze</PostRunAction>
<TestID>6</TestID>
<TestInstanceID>1</TestInstanceID>
<TimeslotDuration>
<Hours>0</Hours>
<Minutes>30</Minutes>
</TimeslotDuration>
<VudsMode>false</VudsMode>
</Run>
'

Invoke-RestMethod -Method Put -Uri $Put_Url -Body $Body -ContentType $content_type -WebSession $websession

0 Likes
1 Solution

Accepted Solutions
Highlighted
Respected Contributor.
Respected Contributor.

Had  a same issue yesterday while using API, the problem in my code was the Method Type, using GET instead of POST.

Change the method of API to run test to POST. This currently look PUT to me "Put_Url".

 

Thanks,

Girish

View solution in original post

0 Likes
6 Replies
Highlighted
Respected Contributor.
Respected Contributor.

Hi Shavan,

Authenticate REST API returns 2 Cookies which needs to be passed in all subsequent REST API call. These 2 Cookies needs to be passed as header in API which you are using to run the test.

Check the response header for Authenticate REST API, you will see 2 cookies - 

Set-Cookie: LWSSO_COOKIE_KEY=*******

Set-Cookie: QCSession=*******

 

Tool like Postman would be able to maintain these Cookies as part of Session, so your API to run Test is passing without adding headers (cookies) explicitly. I observed same when I was using "Advanced REST Client'.

 

Thanks,

Girish

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Hi Girish,

Thanks for your reply.

I am aware of the cookies that need to be passed for executing the test. These cookies are captured from the initial authentication call and stored in the "-SessionVariable websession".

And I am passing the stored cookie value to the PUT request in "-WebSession $websession".

 

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Hi Shavan,

Can you provide a snapshot from Performance Center for your scenario, need to ensure the XML is matching the test you want to run.

 

Thanks,

Girish

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Hi Girish,

But the same xml is working fine when executing from Postman.

 

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.

Had  a same issue yesterday while using API, the problem in my code was the Method Type, using GET instead of POST.

Change the method of API to run test to POST. This currently look PUT to me "Put_Url".

 

Thanks,

Girish

View solution in original post

0 Likes
Highlighted
Trusted Contributor.
Trusted Contributor.

Thanks Girish, you nailed it.

It was my mistake and after changing the Method type to Post the script worked.

Much Appreciated.

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.