Search code examples
azure-devopsazure-devops-rest-apiazure-devops-server-2019

How do you get a list of all project iterations using the Azure DevOps Services .NET SDK?


I'd like to get a list of all the iterations for a given project in a Azure DevOps repository, using the .NET API.

Is there any example of how to do this? The current documentation (https://learn.microsoft.com/en-us/dotnet/api/microsoft.teamfoundation.work.webapi.workhttpclientbase.getteamiterationsasync?view=azure-devops-dotnet) is pretty thin.


Solution

  • Below is a working example of how to achieve this.

    You need to reference Microsoft.TeamFoundation.Work.WebApi.

    public async Task<List<TeamSettingsIteration>> GetProjectIterations(string serverUrl, string projectName)
    {
        var uri = new Uri(serverUrl);
        var creds = new VssClientCredentials(new WindowsCredential(true), new VssFederatedCredential(true), CredentialPromptType.PromptIfNeeded);
    
        var azureDevopsConnection = new VssConnection(uri, creds);
        await azureDevopsConnection.ConnectAsync();
    
        WorkHttpClient azureDevOpsWorkHttpClient = azureDevopsConnection.GetClient<WorkHttpClient>();
        TeamContext teamContext = new TeamContext(projectName);
    
        List<TeamSettingsIteration> results=  await azureDevOpsWorkHttpClient.GetTeamIterationsAsync(teamContext);
        return results;
    }