This work great:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://v-tinmo-12r2:8080/tfs/DefaultCollection2015U2/ScrumStarain/_apis/build/builds?api-version=2.0");
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.Method = "Post";
request.ContentType = "application/json";
Stream stream = request.GetRequestStream();
string json = "{\"definition\":{\"id\":1}}";
byte[] buffer = Encoding.UTF8.GetBytes(json);
stream.Write(buffer, 0, buffer.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.Write(response.StatusCode);
using (var streamReader = new StreamReader(response.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
Console.Read();
But when i'm trying to add parameters its not working.
when I do the POST from powershell its work great but i'm not convert it to json before the call.
$json = "{
'parameters': '{ \'param1\': \'\test\""\',\'param2\': \'\""test2\""\'}',
'definition': {'id': 231}
}"
$build = Invoke-RestMethod -Method Post -UseDefaultCredentials -ContentType application/json -Uri "http://tfs-app:8080/tfs/DefaultCollection/ALM/_apis/build/builds?api-version=2.0" -Body $json
Why its doesn't work with C# web request?
BTW, when I do the call from POSTMAN with this body:
{"definition":{"id":231},"parameters":{"FileToCheckInFullPath":"test"}}
I got:
"{"$id":"1","innerException":null,"message":"This request expects an object in the request body, but the supplied data could not be deserialized.","typeName":"Microsoft.TeamFoundation.Build.WebApi.RequestContentException,
Microsoft.TeamFoundation.Build2.WebApi, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","typeKey":"RequestContentException","errorCode":0,"eventId":3000}"
But when I change the word "parameters" to any other word its work, the build queued but with empty params.
Anyone can help?
Thanks.