无法使用 PAT 针对 Azure DevOps _apis/distributedtask/variablegroups 进行身份验证

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

我是 运行 使用 Powershell 对 Azure DevOps API 的简单调用:

$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)}   

错误显示在:

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

正在摸索,都是按照this and this文章配置的。

奇怪的是 运行 在没有指定项目的情况下针对 API 的调用在处理时没有错误:

$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)}

响应:

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

您的 PAT 似乎无权访问变量组

您可以转到您的 PAT 编辑页面 检查 PAT 是否至少分配了 Read 权限 变量组。请参见下面的屏幕截图。

为您的 PAT 授予适当的权限范围,然后再次尝试调用其余 api。