1
votes

I want list of all bugs in azure devops project.

I found this rest api in microsoft docs -

GET https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=6.0

What parameters do I need to pass here to list only bugs not all work items ?

2
Hi, How about the issue? Does the answer below resolve your question? If yes, you could Accept it as an Answer , so it could help other community members who get the same issues and we could archive this thread, thanks.Vito Liu

2 Answers

1
votes

Agree with Shamrai Aleksander.

We could list all bugs via wiql query and then get the work item detail info via the REST API you shared in the issue description.

Here is power shell script sample:

$connectionToken="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$WorkItemQueryURL = "https://dev.azure.com/{Org name}/{Project name}/{Team name}/_apis/wit/wiql?api-version=6.0" 

$body =@"
{
  "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.TeamProject] = @project AND [System.WorkItemType] = 'Bug'"
}
"@
$WorkItem = Invoke-RestMethod -Uri $WorkItemQueryURL -ContentType "application/json" -Body $body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method POST

Write-host $WorkItem.workItems.id

ForEach ($ID in $WorkItem.workItems.id)
{
   $WorkItemInfoURL = "https://dev.azure.com/{Org name}/{Project name}/_apis/wit/workitems/$($ID)?api-version=6.0" 

   Invoke-RestMethod -Uri $WorkItemInfoURL -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
  
}
2
votes

You have to use wiql here: Get results of a flat work item query.

Web request:

POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=6.1-preview.2

Body:

{
  "query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}