1

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 ?

1
  • 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. Commented Dec 16, 2020 at 7:56

3 Answers 3

2

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"
}
Sign up to request clarification or add additional context in comments.

Comments

1

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)}
  
}

Comments

1

Vito Liu and Shamrai Aleksander solution verified. Below is my code:

$url_base = "https://dev.azure.com/{org}/{project}/"
$url_endpoint = "apis/wit/wiql?$top=True&api-version=7.1-preview.2"
$url = $url_base + $url_endpoint
$PAT = "Your PAT"
$user = ""
$token = [Convert]::ToBase64String([Text.Encoding]::ASCII.Getbytes(("{0}:{1}" -f $user,$PAT)))

$header = @{Authorization = "Basic $token"; 'Content-Type' = application/json}
$body = @{'query' = 'Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = "Task" AND [State] = "Active"}

$response = Invoke-RestMethod -uri $url -Method POST -headers $header -Body ($body | ConvertTo-Json)
$response

The only issue I ran into was the HTTP variable $top which claims to be a INT32 data type in msft documentation is a boolean. When you place in an integer the code returns an error claiming that $top must be a Boolean value.

Does anyone have a solution to limit the amount of queries received?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.