从Visual Studio Team Services REST API获取所有工作项 [英] Hoe to get all work items from Visual Studio Team Services REST API
问题描述
我每天需要获取5000个工作项,并且需要准备一些报告,但是REST API一次仅支持200个插槽,在这种情况下,我将对API进行多次调用.还有其他方法可以一次获取所有工作项吗?
您正在使用哪个版本的TFS?如果您使用的是本地TFS 2018或VSTS,则可以使用REST API-
I need to fetch 5000> work items on daily basis and need to prepare some report but REST API support only 200 slot at a time and in that case I will have do many call to API. Is there any other way to get all work items at once ???
Which version of TFS are you using? If you are using on-premise TFS 2018 or VSTS, then you can use the REST API - Reporting Work Item Revisions - Read Reporting Revisions Get or Reporting Work Item Revisions - Read Reporting Revisions Post to get all the work items:
GET https://{accountName}.visualstudio.com/{project}/_apis/wit/reporting/workitemrevisions?includeLatestOnly=true&api-version=4.1
You can add optional parameters as needed:
GET https://{accountName}.visualstudio.com/{project}/_apis/wit/reporting/workitemrevisions?fields={fields}&types={types}&continuationToken={continuationToken}&startDateTime={startDateTime}&includeIdentityRef={includeIdentityRef}&includeDeleted={includeDeleted}&includeTagRef={includeTagRef}&includeLatestOnly={includeLatestOnly}&$expand={$expand}&includeDiscussionChangesOnly={includeDiscussionChangesOnly}&$maxPageSize={$maxPageSize}&api-version=4.1
For example, we can use below PowerShell script to retrieve all the work items from a specific project (You can also export the result to a *.csv
file, then open in Excel):
Param(
[string]$baseurl = "http://server:8080/tfs/DefaultCollection",
[string]$projectName = "0511ScrumTFVC",
[string]$user = "domain\user",
[string]$token = "password/PAT"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$uri = "$baseurl/$($projectName)/_apis/wit/reporting/workitemrevisions?includeLatestOnly=true"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Clear-Host
Write-Host "Count of Work items"$result.values.count
$wits = @()
foreach ($wit in $result.values)
{
$customObject = new-object PSObject -property @{
"WitID" = $wit.fields.'System.id'
"rev" = $wit.Rev
"Title" = $wit.fields.'System.Title'
}
$wits += $customObject
}
$wits | Select `
WitID,
rev,
Title #|export-csv -Path D:\temp\WITs.csv -NoTypeInformation
这篇关于从Visual Studio Team Services REST API获取所有工作项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!