Quantcast
Channel: Visual Studio Integrate forum
Viewing all articles
Browse latest Browse all 4410

PowerShell Error when queuing a build via Invoke-RestMethod

$
0
0

I have successfully implemented a number of PowerShell scripts to GET information, however I am unable to troubleshoot an error when trying to POST a request to queue a build.

#Queue a build
$BuildReqBody = @{"Definition"=@{"id"=1}; reason='IndividualCI'; priority='High' }

$Response = Invoke-RestMethod -Uri https://MyCo.visualstudio.com/DefaultCollection/MyPorject/_apis/build/requests?api-version=1.0 -Headers $h -Body $BuildReqBody -Method Post -ContentType 'application/json'

The error I am receiving:

Invoke-RestMethod : {"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: postContract","typeName":"System.ArgumentNullException, mscorlib, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
At C:\Projects\Builds\BuildDefs.ps1:24 char:13
+ $Response = Invoke-RestMethod -Uri https://myco.visualstudio.com/DefaultCollect ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

After researching, I cannot find reference to the error above.

Thanks

UPDATE:  I found the answer.   Must convert the body to JSON and pass as -Body

$BuildReqBodyJson = $BuildReqBody | ConvertTo-Json



Viewing all articles
Browse latest Browse all 4410

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>