Highlighted
Absent Member.
Absent Member.
5790 views

Upload Vugen script REST API responses with bad request

I am triying to run the upload script API via SOAP UI as well as java code. I am able to run all other API without any issues but upload scripts responds with the bad request status 400. I refered the following link "http://alm-help.saas.hpe.com/en/Latest/api_refs/Performance_Center_REST_API/Performance_Center_REST_API.htm#scripts.htm" .

But it throws the bad request format .

I used the request headers Content-Type: multipart/form-data as mentined in the reference link but In request example it shows application/xml as shown below

 POST http://<PcServer>/LoadTest/rest/domains/alex-qc/projects/PCdemo/Scripts

Content-Type: application/xml Cookie: LWSSO_COOKIE_KEY={LwssoCookie};QCSession={QCSessionCookie}; <Script xmlns="http://www.hp.com/PC/REST/API">

<TestFolderPath>myTestFolder01\myWebScripts</TestFolderPath>

<Overwrite>true</Overwrite> <RuntimeOnly>true</RuntimeOnly>

<KeepCheckedOut/> </Script> 

 I tried all possible methods but it throws the bad request. Kindly anyone assist me that whatis content type and how request body should construct.

0 Likes
23 Replies
Highlighted
Honored Contributor.
Honored Contributor.

 

Hi,

Request body should contain:

  • A script to be uploaded as multipart/form-data. Only zipped Vugen scripts can be uploaded
  • Upload parameters as text in the following format: <Script xmlns="http://www.hp.com/PC/REST/API"><TestFolderPath>Subject\{existing folder name}</TestFolderPath><Overwrite>true</Overwrite><RuntimeOnly>true</RuntimeOnly><KeepCheckedOut >false</KeepCheckedOut></Script>

 

Example of valid request: (the script context as a byte stream should be  added at the related content stream section)

Note that the boundary value should be different at your request as it is part of the HTTP multipart/form-data request specification.

 

POST http://<pc server>/LoadTest/rest/domains/<domain name>/projects/<project>/scripts HTTP/1.1
Host: <pc server>
Connection: keep-alive
Content-Length: 48483
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryMjZcS52AXCQCgeJA
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,he;q=0.6,ru;q=0.4


------WebKitFormBoundaryMjZcS52AXCQCgeJA
Content-Disposition: form-data; name="aaa"; filename="demo_script_new.zip"
Content-Type: application/x-zip-compressed

<script content as a stream>
------WebKitFormBoundaryMjZcS52AXCQCgeJA
Content-Disposition: form-data; name=""

<Script xmlns="http://www.hp.com/PC/REST/API"><TestFolderPath>aaaa</TestFolderPath><Overwrite>true</Overwrite><RuntimeOnly>true</RuntimeOnly><KeepCheckedOut>false</KeepCheckedOut></Script>
------WebKitFormBoundaryMjZcS52AXCQCgeJA--

Highlighted
Absent Member.. Absent Member..
Absent Member..

Same Problem I am facing to upload the scripts using REST API.

I have passed all correct parameters and request contants but no luck  

Action.c(78): Error -26631: HTTP Status-Code=400 (Bad Request) .

Please help if someone has solution on the same.

 

 

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Hi Dc1,

Are you still getting the error 400 following the instructions I wrote above?

Regards,
Eyal

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Hi @EyalR,

I am currently looking how to upload a script from my workstation to ALM/PC. For now I am using HP Loadrunner to create a working situation. Later on I will try to script it in VB.net or something.

I also get the HTTP Status-Code=400 (Bad Request) returned.

From my Loadrunner script I am able to login with this code

web_add_header("Authorization",
		"Basic <user:password>");

web_rest("PCS-SignIn",
        "URL=http://<PC-Server>/LoadTest/rest/authentication-point/authenticate",
        "Method=GET",
        LAST);

 

That works fine.

Also the logout works fine: 

web_rest("PCS-SignOut",
        "URL=http://<PCServer>/LoadTest/rest/authentication-point/logout",
        "Method=GET",
        LAST);

But I haven't nailed the upload request yet.

This is my request: 

(where parameter "fileDataParameter" = "PK\x03\x04\x14\x00\x00: ... ... ... etc."  the stream containing the ZIP-file)

     web_add_header("content-type", 
        "multipart/form-data; boundary=----WebKitFormBoundaryMjZcS52AXCQCgeJA");

web_rest("PCS-Upload", "URL=http://<PCserver>/LoadTest/rest/domains/TESTDOMAIN/projects/TestProject/scripts/", "Method=POST", "Body=" "------WebKitFormBoundaryMjZcS52AXCQCgeJA" "Content-Disposition: form-data; name=\"aaa\"; filename=\"Demo.zip\"" "Content-Type: application/x-zip-compressed"
"{fileDataParameter}" "------WebKitFormBoundaryMjZcS52AXCQCgeJA" "Content-Disposition: form-data; name=\"\"" "<Script xmlns=\"http://www.hp.com/PC/REST/API\">" "<TestFolderPath>Subject\Scripts</TestFolderPath>" "<Overwrite>true</Overwrite>" "<RuntimeOnly>true</RuntimeOnly>" "<KeepCheckedOut/>" "</Script>" "------WebKitFormBoundaryMjZcS52AXCQCgeJA--" "", LAST);

The response I retrieve is something like:  

PCS_Action.c(34):     <Exception xmlns="http://www.hp.com/PC/REST/API">\r\n
PCS_Action.c(34):       <ExceptionMessage>Request is not properly formatted. For script upload, a multipart/form
PCS_Action.c(34):     -data type request should be sent containing a PC API Script request and a zipped script f
PCS_Action.c(34):     ile.</ExceptionMessage>\r\n
PCS_Action.c(34):       <ErrorCode>1600</ErrorCode>\r\n
PCS_Action.c(34):     </Exception>

 Can you help me out? Or someone else?

NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.
0 Likes
Highlighted
New Member.

What version of PC is able to do this?

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Hi @EyalR

I Learned a few things regarding the boundaries:
- You close the boundary at the end of the request with '--' (Without the single quoutes)
- Everytime you use the boundary it should start with '--' (Without the single quoutes)

This is my Current request but stills gives a HTTP Status-Code=400 (Bad Request)

 	web_add_header("content-type",
		"multipart/form-data; boundary=ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5");

	web_rest("PCS-Upload",
        "URL=http://<PCServer>/LoadTest/rest/domains/TESTDOMAIN/projects/TestProject/scripts/",
        "Method=POST",
        "Body="
		"--ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5" 
		"Content-Disposition: form-data; name=\"aaa\"; filename=\"Demo.zip\""
		"Content-Type: application/x-zip-compressed" 
                "{FileDataParameter}" 
		"--ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5" 
        "Content-Disposition: form-data; name=\"\""
        "<Script xmlns=\"http://www.hp.com/PC/REST/API\">"
 			"<TestFolderPath>Subject\Scripts</TestFolderPath>"
 			"<Overwrite>true</Overwrite>"
 			"<RuntimeOnly>true</RuntimeOnly>"
 			"<KeepCheckedOut/>"
		"</Script>"
		"--ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5--" 
		"",
        LAST);

Detailed Error:

PCS_Action.c(72):     <Exception xmlns="http://www.hp.com/PC/REST/API">\r\n
PCS_Action.c(72):       <ExceptionMessage>Request is not properly formatted. For script upload, a multipart/form
PCS_Action.c(72):     -data type request should be sent containing a PC API Script request and a zipped script f
PCS_Action.c(72):     ile.</ExceptionMessage>\r\n
PCS_Action.c(72):       <ErrorCode>1600</ErrorCode>\r\n
PCS_Action.c(72):     </Exception>
NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Hello @kvaga 

I am using PC 12.50.
I haven't got it working yet.
Login and logout work fine and because the server responses with the message that the MultiPart/form-data is not well-formatted, I conclude that the authentication is ok.

NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

 

The REST API to upload script is available from PC 12.50

0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

@EyalR

EyalR, I see you are still looking at this thread.
Could you please look at my case up in this thread?
Still a bad-reqeust...

TY 🙂

 

NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.

Hi @EyalR

Okay the file is uploaded now to PC server but not available in PC yet, because of a HTTP Status-Code=500. (The file is uploaded to: ..\HP\Performance Center Server\orchidtmp\TempFiles\API\<GUID>\demo.zip)

This is the request with a new error message: HTTP Status-Code=500 (Internal Server Error)

 

 	web_add_header("content-type",
		"multipart/form-data; boundary=ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5; encoding=UTF-8");

	web_rest("PCS-Upload",
        "URL=http://<PCserver>/LoadTest/rest/domains/TESTDOMAIN/projects/TestProject/scripts/",
        "Method=POST",
        "Body="
		"--ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5\r\n"
		"Content-Disposition: form-data; name=\"Demo\"; filename=\"C:\\Users\\<Username>\\Documents\\VuGen\\Scripts\\ALMREST001\\Demo.zip\""
		"\r\n"
		"Content-Type: application/x-zip-compressed" 
		"\r\n\r\n"
        "{FileDataParameter}\r\n" 
		"--ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5"
		"\r\n"
        "Content-Disposition: form-data; name=\"\""
        "\r\n\r\n"
        "<Script xmlns=\"http://www.hp.com/PC/REST/API\">"
 			"<TestFolderPath>Demo</TestFolderPath>"
 			"<Overwrite>true</Overwrite>"
 			"<RuntimeOnly>true</RuntimeOnly>"
 			"<KeepCheckedOut/>"
		"</Script>"
		"\r\n\r\n"
		"--ThisIsMyPCBoundaryVGhpc0lzTXlQQ0JvdW5kYXJ5--"
		"\r\n"
		"",
        LAST);

Response:

 

 

PCS_Action.c(72):     <Exception xmlns="http://www.hp.com/PC/REST/API">\r\n
PCS_Action.c(72):       <ExceptionMessage>Operation failed.</ExceptionMessage>\r\n
PCS_Action.c(72):       <ErrorCode>1001</ErrorCode>\r\n
PCS_Action.c(72):     </Exception>

I can open the ZIP File on the PC server. The file is uploaded to: ..\HP\Performance Center Server\orchidtmp\TempFiles\API\<GUID>\demo.zip

 

In the logfile (..\HP\Performance Center Server\orchidtmp\LTLogger\w3wp\log.txt)there is a message:

System.NotSupportedException: The given path's format is not supported.
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at Ionic.Zip.ZipFile.get_ReadStream()
   at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
   at Ionic.Zip.ZipFile.Read(String fileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)
   at HP.PC.ScriptUploader.Rest.RestScriptUploader.IsMetadataExists(String zipFileName)
   at HP.PC.API.Impl.ScriptManager.UploadScript(ScriptRequest scriptRequest, String zippedScriptLocation)
   at HP.PC.API.PcApiEngine.UploadScript(ScriptRequest scriptRequest, String zippedScriptLocation)
   at HP.PC.Web.API.Api_Controllers.ScriptsController.UploadScript(String domain, String project)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
   at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)

 

System.NotSupportedException: The given path's format is not supported.
Which path? What format?

Thanks in advance.

NB: If this solves your problem / helps you on the way, consider acknowledging with Kudos. To kudo a post, select the thumbs up icon in the gray square by the post in the thread.
0 Likes
Highlighted
Honored Contributor.
Honored Contributor.



HI @asr_Dennis,

Note that as long as the network data being sent is as I wrote above the request should succeed.

Regarding the error you get you can first record the data being sent to PC server using a network sniffer / fiddler and verify that you are sending the expected data structure.
You can also run the script with extended log enabled.


In PC 12.53 there is a new REST API editor that can be used to test and add as a step in Vugen script.
For more information see:
http://community.hpe.com/t5/LoadRunner-and-Performance/New-REST-API-functionality-in-VuGen-with-LoadRunner-12-53/ba-p/6860181


Regards,
Eyal
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.