when I would like to expand the relations / any of the expand options in Azure DevOps 'Get WorkItem' api call, see documentation
I can't get any usable results, instead I get a warning, that the value of the expand parameter is not valid.
When I send my call:
$workItem = Invoke-VSTeamRequest -Url "https://dev.azure.com/{org}/{project}/_apis/wit/workitems/{id}?api-version=7.1-preview.3&$expand=relations"
I get the error message:
"Message": "The value \u0027relations\u0027 is not valid for Nullable\u00601.\r\n"
When I use
$workItem = Invoke-VSTeamRequest -Url "https://dev.azure.com/{org}/{project}/_apis/wit/workitems/{id}?api-version=7.1-preview.3&expand=relations"
(without the preceding $), the parameter is ignored and I miss the required 'relations' array. Changing the api version has no effect.
Sorry, but I really have a knot in my brain actually. :(
Any help would be appreciated.
"Message": "The value \u0027relations\u0027 is not valid for Nullable\u00601.\r\n"
To solve this issue, we need to escape the $
character in the URL:
For example:
https://dev.azure.com/org/project/_apis/wit/workitems/workitemid?`$expand=relations&api-version=7.1-preview.3
You can use the following PowerShell sample:
$token = "PAT"
$url="https://dev.azure.com/{Org}/{Project}/_apis/wit/workitems/{ID}?`$expand=relations&api-version=7.1-preview.3"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$response = Invoke-RestMethod -Uri $url -Headers @{Authorization = "Basic $token"} -Method Get -ContentType application/json
Write-Host "$response"