2016-08-19 16 views
1

如何使用REST API從VSTS獲取工作項目清單?通過REST API的VSTS工作項目清單

根據documentationids參數是可選的,但是當我省略它時,我得到一個404錯誤。 如果我添加ids參數,我可以得到這些項目。

失敗的請求:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?api-version=1.0

繼承請求:
GET https://{account}.visualstudio.com/DefaultCollection/_apis/wit/workitems?ids=252&api-version=1.0

認證是兩個相同的。

完全解決的問題是:獲得特定VSTS項目

+0

你有任何機會解決這個? – Ivan

+0

不,還不能解決它 – fra

+0

@fra你能告訴我你是如何實現身份驗證嗎?你如何獲得令牌以及如何使用api發送令牌以獲取工作項目? 在此先感謝 –

回答

0

的關鍵是使用WIQL API的一部分,而不是工作項目一個所有功能。 例如獲得的某種類型的使用這種工作項的平面列表: https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#a-flat-query

例在PowerShell中(顯示在封閉狀態的所有用戶故事):

# using env vars passed from VSTS build 
$collectionuri = $Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI 
$token = $Env:SYSTEM_ACCESSTOKEN # need to configure build to allow passing OAuth tokens 

$basicAuth = "{0}:{1}"-f "ivan-the-terrible", $token 
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth) 
$basicAuth = [System.Convert]::ToBase64String($basicAuth) 
$headers = @{Authorization=("Basic {0}"-f $basicAuth)} 

$WorkItemType = 'User Story' 

$url = $collectionuri + 'DefaultCollection/_apis/wit/wiql?api-version=1.0' 

$WIQL_query = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = '" + $WorkItemType + "' AND [State] = 'Closed' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc" 
$body = @{ query = $WIQL_query } 
[email protected]($body) | ConvertTo-Json 

$response = Invoke-RestMethod -Uri $url -headers $headers -Method Post -ContentType "application/json" -Body $bodyJson 

$workitems = $response.workItems 

Write-Host "Found" $workitems.Count "work items of type:" $WorkItemType 
相關問題