Reputation: 33
I am trying to get a complete list of projects in VSTS. Using this code gives me the first 100 projects, but I can find no way to specify/ask for more
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...
}
I know that there are more than 100 projects, but it will only every return that many. Is there some way to incorporate a "TOP 1000" into the request? What would that syntax be? Thanks
Works now that I changed one line to read:
HttpResponseMessage response = client.GetAsync("_apis/projects?$top=250&stateFilter=All&api-version=1.0").Result;
Upvotes: 3
Views: 1234
Reputation: 58980
I'm surprised the API documentation is incomplete. You can specify a $top
parameter.
Ex: _apis/projects?$top=250&version=1.0
Upvotes: 5