我正在尝试使用以下REST API获取我的VSTS项目迭代列表
string _personalAccessToken = "mypersonalAccessToken"; // this PAT has Project and team (read, write, and manage) and Work items (read and write) scope
string _credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "", _personalAccessToken)));
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://*myUserAccount*.visualstudio.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
var response = client.GetAsync("DefaultCollection/*MyProjectName*/*MyTeamName*/_apis/work/TeamSettings/Iterations?api-version=v2.0-preview.1").Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
}
我的REST调用正在执行,没有任何错误(返回200代码),空值。虽然在我的项目中,我们至少有50次迭代,但我没有获取具有上述代码的那些。
我不确定我在哪里弄错了。任何帮助将不胜感激。
答案 0 :(得分:3)
代码没问题。
请参阅这些步骤以检查该团队的迭代。
更新:
如果省略团队名称,它将检索默认团队的迭代。
默认团队:转到团队项目的管理页面>概要>更改默认团队
选择默认团队的迭代:转到团队项目的管理页面>工作>迭代>单击默认团队的设置。
如果您希望获得团队项目的所有迭代,可以使用get the root iteration tree REST API,也可以直接使用此代码(添加/安装Microsoft Team Foundation Server Extended Client包):
var u = new Uri("https://starain.visualstudio.com");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.VssBasicCredential(string.Empty, "[pat]"));
var connection = new VssConnection(u, c);
var workItemTracking = connection.GetClient<WorkItemTrackingHttpClient>();
Microsoft.TeamFoundation.Core.WebApi.ProjectHttpClient projClient = connection.GetClientAsync<Microsoft.TeamFoundation.Core.WebApi.ProjectHttpClient>().Result;
var projects= projClient.GetProjects().Result;
foreach(var p in projects.Where(pro=>pro.Name=="Scrum2015"))
{
var iteration = workItemTracking.GetClassificationNodeAsync(project: p.Name, structureGroup: Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.TreeStructureGroup.Iterations, depth: 5).Result;
GetIterations(iteration);
}
static void GetIterations(Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItemClassificationNode currentIteration)
{
Console.WriteLine(currentIteration.Name);
if(currentIteration.Children!=null)
{
foreach (var ci in currentIteration.Children)
{
GetIterations(ci);
}
}
}