How can I find all work items in a given board column via Azure DevOps API?

六月ゝ 毕业季﹏ 提交于 2021-01-28 13:01:08

问题


I’m building an application that fetches information from our Azure DevOps board. One of the tasks is to get all tickets present in a given column.

I’ve spent quite a lot of time reading through their docs but all the methods rely on you passing the IDS you want to get back, while what I’m looking for is for the API to tell me what work items do exist in a given column.


回答1:


The easiest way to find the work items in a board column would be to use the Wiql - Query by Wiql API. The usage will look very similar to how you just use the UI query functionality to find work items.

Given some work items in this kind of board state (using Basic template):

Example in PowerShell below:

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$uri = "https://dev.azure.com/{organization}/{project}/{team}/_apis/wit/wiql?api-version=6.0"

$body = @{
  "query" = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.BoardColumn] = 'Doing'"
} | ConvertTo-Json -Depth 10

Invoke-RestMethod -Method Post -Uri $uri -Headers $AzureDevOpsAuthenicationHeader -Body $body -ContentType 'application/json' |
    Select-Object -ExpandProperty workItems

Returns:

id url                                                                                     
-- ---                                                                                     
26 https://dev.azure.com/{organization}/{project}/_apis/wit/workItems/26


来源:https://stackoverflow.com/questions/63587269/how-can-i-find-all-work-items-in-a-given-board-column-via-azure-devops-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!