Hoe to get all work items from Visual Studio Team Services REST API

╄→尐↘猪︶ㄣ 提交于 2021-01-29 00:38:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!