0

need help here: I have this api which i run in Postman (https://dev.azure.com/abc/Abc/_apis/build/builds/24169/workitems?api-version=4.1), I get result as

{
    "count": 50,
    "value": [
        {
            "id": "21610",
            "url": "https://dev.azure.com/abc/_apis/wit/workItems/21610"
        },
        {
            "id": "21606",
            "url": "https://dev.azure.com/abc/_apis/wit/workItems/21606"
        }]}

I need to call this in Powershell, and get a list of all IDs. I am doing this way but I am not getting anything..what wrong am I doing?

Function GET-RELEASEWIT {
$AzureDevOpsPAT ='psgklxbjircg5g5fda'
    $AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$uriAcc = "https://dev.azure.com/abc/ABC/_apis/build/builds/24169/workitems?api-version=4.1"
write-host $uriAcc
$responseRelW = Invoke-RestMethod -Uri $uriAcc -Method get -Headers $AzureDevOpsAuthenicationHeader
write-host $responseRelW
$BID = @()
$BID += $responseRelW.value.id

write-host "********START****************"
write-host $BID

}
2
  • There's no username component in your authorization header? Commented Mar 13, 2021 at 15:46
  • username is not required if you pass api in postman you will see.. it can be left blank Commented Mar 13, 2021 at 17:42

1 Answer 1

1

I've tried the below and it works. Only difference I can see is that I've used UTF8.GetBytes instead of ASCII.GetBytes when converting the PAT token to a base64 string, which shouldn't cause any difference since the character mappings are the same.

$uri = "https://dev.azure.com/abc/ABC/_apis/build/builds/24169/workitems?api-version=4.1"
$AzureDevOpsPAT ='psgklxbjircg5g5fda'
$B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$AzureDevOpsPAT"))
$headers = @{ Authorization = "Basic $B64Pat" }
Invoke-RestMethod -Uri $uri -Headers $headers

Note the URI and PAT token are obviously different when I tested this, but this should work for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.