Sergey
Sergey

Reputation: 391

Unable to authenticate against Azure DevOps _apis/distributedtask/variablegroups using PAT

I'm running a simple call to Azure DevOps API using Powershell:

$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "{USER}","{PAT}")))
$url = "https://dev.azure.com/{ORG_NAME}/{PROJECT_NAME}/_apis/distributedtask/variablegroups/{ID}?api-version=5.0-preview.1"
Invoke-RestMethod -Uri $url -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}   

The error is shown after:

Invoke-RestMethod: Response status code does not indicate success: 401 (Unauthorized).

Trying to figure out what's wrong, all is configured according to this and this articles.

The strange is that running a call against API without specifying the project is processed without errors:

$url2 = "https://dev.azure.com/{ORG_NAME}/_apis/projects?api-version=2.0" 
Invoke-RestMethod -Uri $url2 -Method Get -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

Response:

count value
----- -----
    5 {@{id=xxxxxxx-89f3-46b0-af7e-xxxxxxx; name=Xxxxx; description=F…

Upvotes: 0

Views: 531

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

It seems your PAT is not authorized to access the Variable groups.

You can go to your PAT edit page to check if the PAT was assigned at least the Read permission for Variable groups. See below screenshot.

Grant the proper permission scope for your PAT, and try calling the rest api again.

enter image description here

Upvotes: 1

Related Questions