问题
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 ???
回答1:
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
来源:https://stackoverflow.com/questions/52154896/hoe-to-get-all-work-items-from-visual-studio-team-services-rest-api