VSTS - 使用API​​获取所有项目的列表,而不仅仅是前100名

时间:2018-06-04 20:12:01

标签: c# api azure-devops

我想在VSTS中获得完整的项目列表。使用此代码为我提供了前100个项目,但我找不到指定/要求更多

的方法
using (var client = new HttpClient())
{
    client.BaseAddress = new Uri("https://{accountname}.visualstudio.com/DefaultCollection");
    client.DefaultRequestHeaders.Accept.Clear();
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", {credentials});

    HttpResponseMessage response = client.GetAsync("_apis/projects?stateFilter=All&api-version=1.0").Result;

    if (response.IsSuccessStatusCode)
    {
        responseString = response.Content.ReadAsStringAsync().Result.ToString();
    }
    else
    {
        //failed
    }
}

// Convert responseString into a json Object
RootObj jsonObj = JsonConvert.DeserializeObject<RootObj>(responseString);
Console.WriteLine("Found " + jsonObj.Count + " projects");

//Do stuff
foreach (var obj in jsonObj.Value)
{
    //foreach project...
}

我知道有超过100个项目,但只会返回那么多项目。有没有办法在请求中加入“TOP 1000”?那句法是什么?感谢

现在我改变了一行来阅读:

HttpResponseMessage response = client.GetAsync("_apis/projects?$top=250&stateFilter=All&api-version=1.0").Result;

1 个答案:

答案 0 :(得分:5)

我很惊讶API文档不完整。您可以指定$top参数。

例如:_apis/projects?$top=250&version=1.0