2016-08-19 18 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 
相关问题