cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible for TestRunner API without cURL using PowerShell Invoke Method

SOLVED
kgrandy
New Contributor

Is it possible for TestRunner API without cURL using PowerShell Invoke Method

Trying to avoid running cURL commands in our architecture.  Is it possible for TestRunner API without cURL using PowerShell Invoke Method

 

I seem to be haveing difficulty here is the psude code I am trying to execute...

 

PS C:\Users\%USER%> Invoke-RestMethod -Method POST -ContentType "application/json" -uri "http://localhost:1880/1/suites" -Body @C:\source\apiTest.zip
Invoke-RestMethod : {"success":false,"errorMessage":"The specified data is not a valid ZIP file."}
At line:1 char:1
+ Invoke-RestMethod -Method POST -ContentType "application/json" -uri " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

1 ACCEPTED SOLUTION

Accepted Solutions
Hudson1998
Occasional Visitor

Re: Is it possible for TestRunner API without cURL using PowerShell Invoke Method

Multipart/form-data does work when adding as content type. The problem I had here is the API needed some parameters to accept raw content, then I was able to use -InFile \path\to\file and upload using Invoke-RestMethod subway gift card balance

View solution in original post

3 REPLIES 3
tphillips
Community Leader

Re: Is it possible for TestRunner API without cURL using PowerShell Invoke Method

Are you sure you've set the Body correctly? Usually the body is in key-value pairs.

Also make sure you're using the correct content-type for the upload endpoint, often it's "multipart/form-data" for file upload forms.

 

https://stackoverflow.com/questions/22770213/using-powershell-invoke-restmethod-to-post-large-binary...


--------------------
QA Systems Architect
Hudson1998
Occasional Visitor

Re: Is it possible for TestRunner API without cURL using PowerShell Invoke Method

Multipart/form-data does work when adding as content type. The problem I had here is the API needed some parameters to accept raw content, then I was able to use -InFile \path\to\file and upload using Invoke-RestMethod subway gift card balance

View solution in original post

kgrandy
New Contributor

Re: Is it possible for TestRunner API without cURL using PowerShell Invoke Method

I was able to upload via PowerShell using this code:

 

$Test = Invoke-RestMethod -uri "http://localhost:1880/1/suites" -ContentType "application/zip" -Method Post -Infile C:\tests\api_tests\apiTest.zip

 

now we are having issues with authentication... can I just wrap that into the header?

New Here?
Join us and watch the welcome video:
Announcements