Reputation: 81
I have a work item in Azure DevOps Boards with "System.WorkItemType": "Template" and "System.Title": "Sample" and I need to retrieve the workitem details using rest api.
Upvotes: 0
Views: 1367
Reputation: 8298
In the Azure DevOps, work item ID a unique identifier and we can create multiple work items with the same name.
As a workaround, we could run the wiql query to get workitems based on Title, then get the work item ID and list the work item details. You could check below script.
In my script, I listed the details of all work items whose title is test
and work item type is User Story
.
$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] = 'User Story' AND [System.Title] = 'test' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
"@
$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.1-preview.3"
Invoke-RestMethod -Uri $WorkItemInfoURL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
}
Result:
and Azure DevOps query result:
Upvotes: 1