使用Visual Studio Team Services REST API时遇到困难 [英] Difficulty using Visual Studio Team Services REST API

查看:57
本文介绍了使用Visual Studio Team Services REST API时遇到困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为Visual Studio Team Services创建一个新的迭代,最初只需使用LINQPad编写代码。  但是我不了解我需要传递给VSTS的有效负载的API文档。


直觉我认为你应该传递迭代的名称等等但是这个失败了。   API文档似乎表明您传入带有guid的ID


" {\" id \":\" a589a806-bf11-4d4f- a031-c19813331553 \"}" ;;


然后我收回以下内容:


{" $ id":" 1"," innerException":null," message":"指定的参数超出了有效值的范围。\\\\ nParameter name:iteration.Id"," typeName":" System。 ArgumentOutOfRangeException,mscorlib,
Version = 14.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089"," typeKey":" ArgumentOutOfRangeException"," errorCode":0," eventId":0}


这告诉我,不存在具有此id的迭代。  我想创建一个新的迭代。  我所知道的是,我的帐户没有权限,但我希望我的调查会以一条消息结束,以表明我和
我可以将脚本带给我的经理并从那里继续前进。 / p>

以下是我正在使用的代码



void Main()

{

字符串凭据= Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format(" {0}: {1}","",Util.GetPassword(" vsts.access"))));




//使用httpclient

使用(var client = new HttpClient())

{

client.BaseAddress = new Uri(" https:// {instance} .visualstudio.com:");   //我们帐户的网址

client.DefaultRequestHeaders.Accept.Clear();

client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue(" application / json"));

client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(" Basic",credentials);



// var postBody =" {\" id \" :\"" + System.Convert.ToString(Guid.NewGuid())+" \"}" ;;

var postBody =" {\" id\":\" a589a806-bf11-4d4f-a031-c19813331553 \"}" ;;



//连接到REST端点           

HttpResponseMessage response = client.PostAsync(" DefaultCollection / {Team} / _ apis / work / TeamSettings / Iterations?api -version = v2.0",new StringContent(postBody,Encoding.UTF8," application / json"))。结果;





response.Content.ReadAsStringAsync()。Result.Dump();

}



}



非常感谢任何帮助。  我是这个领域的新手,所以我很抱歉,如果这是我的小学生错误,但我真的被卡住了,找不到任何做过同样事情的人的帖子。



谢谢,



Sunil

解决方案

您好SunilC_Rexson,


根据您的描述,它与VSTS更相关,我们会移动您的请访问VSTS论坛以获得更好的支持。


感谢您的理解。


祝你好运,


Cole Wu


I am trying to create a new iteration to Visual Studio Team Services, initially by just writing code using LINQPad.  However I do not understand the API documentation in terms of the payload I need to pass to VSTS.

Intuitively I thought you should pass the name of the iteration and so on but this failed.  The API documentation seems to indicate you pass in an id with a guid

"{\"id\":\"a589a806-bf11-4d4f-a031-c19813331553\"}";

but then I get back the following:

{"$id":"1","innerException":null,"message":"Specified argument was out of the range of valid values.\r\nParameter name: iteration.Id","typeName":"System.ArgumentOutOfRangeException, mscorlib, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089","typeKey":"ArgumentOutOfRangeException","errorCode":0,"eventId":0}

This says to me that an iteration with this id doesn't exist.  I would like to create a new iteration.  What I do know is that my account doesn't have permission but I was hoping that my investigation would end in a message to indicate that and I could take the script to my manager and go forward from there.

Here is the code I am using

void Main()
{
string credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", "", Util.GetPassword("vsts.access"))));


//use the httpclient
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://{instance}.visualstudio.com:");  //url of our account
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);

//var postBody = "{\"id\":\"" + System.Convert.ToString(Guid.NewGuid()) + "\"}";
var postBody = "{\"id\":\"a589a806-bf11-4d4f-a031-c19813331553\"}";

//connect to the REST endpoint            
HttpResponseMessage response = client.PostAsync("DefaultCollection/{Team}/_apis/work/TeamSettings/Iterations?api-version=v2.0",new StringContent(postBody, Encoding.UTF8, "application/json")).Result;


response.Content.ReadAsStringAsync().Result.Dump();
}

}

Any help would be much appreciated.  I'm pretty new to this area so I apologise if this is a schoolboy error on my part but I'm really stuck and cannot find any posts of anyone who has done the same.

Thanks,

Sunil

解决方案

Hi SunilC_Rexson,

According to your description, it's more related to VSTS, we'll move your thread to VSTS forum for better support.

Thank you for your understanding.

Best regards,

Cole Wu


这篇关于使用Visual Studio Team Services REST API时遇到困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆