'Impossible to get the latest build using Azure DevOps API

I'm trying to get it using this GET request:

https://dev.azure.com/LumiaWOA/Boot%20Shim/_apis/build/latest/UEFI%20PreLoader Build?branchName=msm8994-pcie&api-version=5.0-preview.1

All I get is this response:

{
    "$id": "1",
    "innerException": null,
    "message": "Cannot serialize type Microsoft.TeamFoundation.Build.WebApi.Build, because the security requirements are not met  Namespace:33344d9c-fc72-4d6f-aba5-fa317101a7e9, RequestedPermissions:1, DataspaceIdentifier: 328eea29-7d2f-4cdf-b928-d58c53d8f29d",
    "typeName": "System.InvalidOperationException, mscorlib",
    "typeKey": "InvalidOperationException",
    "errorCode": 0,
    "eventId": 0
}

I don't understand why I'm getting that error, since the builds are public for everyone: Please, check it: https://dev.azure.com/LumiaWoA/Boot%20Shim/_build?definitionId=3

But it shows this error.



Solution 1:[1]

you are omitting authorization this sample works for me

$uri = "your uri"
$pat = "your PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $base64AuthInfo))
$headers.Add("Content-Type", "application/json")

Invoke-RestMethod -Uri $uri -Headers $headers -Method GET

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David B.