如何使用 rest api 调用列出 azure devops 项目中的所有错误?
How to list all bugs in azure devops project using rest api call?
我想要 azure devops 项目中所有错误的列表。
我在微软文档中找到了这个休息 api -
获取https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=6.0
我需要在此处传递什么参数才能仅列出错误而不是所有工作项?
你必须在这里使用 wiql: Get results of a flat work item query.
网络请求:
POST
https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=6.1-preview.2
正文:
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
同意 Shamrai Aleksander 的观点。
我们可以通过 wiql 查询列出所有错误,然后通过您在问题描述中共享的 REST API 获取工作项详细信息。
这是力量 shell 脚本示例:
$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)}
}
我想要 azure devops 项目中所有错误的列表。
我在微软文档中找到了这个休息 api -
获取https://dev.azure.com/{organization}/{project}/_apis/wit/workitems?ids={ids}&api-version=6.0
我需要在此处传递什么参数才能仅列出错误而不是所有工作项?
你必须在这里使用 wiql: Get results of a flat work item query.
网络请求:
POST https://dev.azure.com/{organization}/{project}/_apis/wit/wiql?api-version=6.1-preview.2
正文:
{
"query": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
}
同意 Shamrai Aleksander 的观点。
我们可以通过 wiql 查询列出所有错误,然后通过您在问题描述中共享的 REST API 获取工作项详细信息。
这是力量 shell 脚本示例:
$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)}
}