【问题标题】:VSTS - Use API to get a list of all projects, not just top 100VSTS - 使用 API 获取所有项目的列表,而不仅仅是前 100 个项目
【发布时间】:2018-06-04 20:12:01
【问题描述】:

我正在尝试获取 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;

【问题讨论】:

    标签: c# api azure-devops


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    相关资源
    最近更新 更多