简体   繁体   中英

How to list work items present on Azure Board using API?

I used boards API in order to get work items present on Azure boards(at user story,feature & epic levels) but the boards API is returning the schema of the team board but I need list of work items present on the board.

Any suggestions?

Please check this Microsoft documentation .

I did almost the same during migration from azure server to devops services.

There are at least 2 ways of programming against azure devops.

  1. REST API
  2. .NET client libraries

Simply examples you can find here: azure devops work items example github

lets focus on 2).Net client libraries, in a nutshell to answer your question: The idea is to get all id`s what you are looking for and than download the appropriate work items.

var serverConnection = new VssConnection(YourUri, new VssBasicCredential(string.Empty, YourPAT));

var wiql = new Wiql()
        {
            Query =
                "SELECT [System.Id], [System.Title] " +
                "FROM workitem " +
                "WHERE " +
                "[System.TeamProject] = 'YourProject' " +
                "AND ([System.State] = 'Active'" + "OR [System.State] = 'New' )" +
                "AND ([System.WorkItemType] = 'User Story' OR [System.WorkItemType] ='Feature')" +
                "ORDER BY [System.ChangedDate] DESC"
        };
var queryItems = wiClient.QueryByWiqlAsync(wiql).Result;
        var queriedIds = queryItems.WorkItems.Select(wiReference => wiReference.Id).ToArray();
        var listOfWorkItems = new List<WorkItem>();
        // Get workItems, limited to 200 each download
        for (int i = 0; i < queriedIds.Length; i += 200)
        {
            var subQueriedIds = queriedIds.Skip(i).Take(200).ToArray();
            if (subQueriedIds.Any())
                listOfWorkItems.AddRange(wiClient.GetWorkItemsAsync("YourProject", subQueriedIds, null, null, WorkItemExpand.All).Result);
        }

listOfWorkItems now includes all of your workitems which you defined by the query. There is also a nice addon for azure available on the marketplace which is so called wiql editor on azure marketplace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM