I can't figure out what is the problem with the code for a few days.. Can you guys have a look and say what I have done wrong? Organizaiton name and project name are put correct in the code.
This is the error message shown on PowerShell ISE:
Invoke-RestMethod : Cannot send a content-body with this verb-type. At \Project\DevopTask.ps1:47 char:17 + ... $response = Invoke-RestMethod -Uri $url -headers $headers -Method Get ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], ProtocolViolationException + FullyQualifiedErrorId : System.Net.ProtocolViolationException,Microsoft.PowerShell.Commands.InvokeRestMet hodCommand
$collectionuri = $Env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI
$token = $Env:SYSTEM_ACCESSTOKEN # need to configure build to allow passing OAuth tokens
$basicAuth = "{0}:{1}" -f '', 'token~~fdsafdsa'
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes(":$($basicAuth)")
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}"-f $basicAuth)}
$WorkItemType = 'Recently updated'
$url = $collectionuri + 'https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/wit/queries/test/wiql?api-version=5.0'
$WIQL_query = "select [System.Id], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.IterationPath] from WorkItems where [System.TeamProject] = @project and [System.Id] in (@recentProjectActivity) and not [System.State] in ('Closed', 'Inactive', 'Completed') and [System.IterationPath] Under 'Sprint number two' order by [System.ChangedDate] desc"
$body = @{ query = $WIQL_query }
$bodyJson=@($body) | ConvertTo-Json
$response = Invoke-RestMethod -Uri $url -headers $headers -Method Get -ContentType "application/json" -Body $bodyJson
$workitems = $response.workItems
Write-Host "Found" $workitems.Count "work items of type:" $WorkItemType