2016-08-19 16 views
1

REST APIを使用してVSTSから作業項目のリストを取得するにはどうすればよいですか?VSTS作業項目リスト(REST API経由)

documentationによれば、idsのパラメータはオプションですが、省略すると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

認証の両方に対して同じです。

解決するための完全な問題がある:キーはAPIではなく、作業項目1のWIQL一部を使用することです特定VSTSプロジェクトに

+0

あなたが万が一これを解決しましたか? – Ivan

+0

いいえ、まだ解決できませんでした – fra

+0

@fra認証の実装方法を教えてください。あなたはどのようにトークンを取得し、作業項目を取得するためにAPIを使ってトークンを送信するのですか? ありがとうございます –

答えて

0

をすべての機能を取得します。 PowerShellで https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql#a-flat-query

例(閉じた状態で、すべてのユーザーストーリーを示して)::いくつかのタイプを使用の作業項目のフラットリストにこの取得する例

# 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 
関連する問題