skip to Main Content

I’m using the GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/approvals?api-version=7.1-preview.1 call
I know that project and organization is correct, since I’m making other calls that work as expected.
The above call should, according to the documentation list all the approvals, but I’m getting:

Query for approvals failed. A minimum of one query parameter is required.rnParameter name: queryParameters.

I do not know that queryParameters I have to set, since the documentation does not dictate this for listing.
Any ideas out there?

2

Answers


  1. Test with the same Rest API and reproduce the same issue.

    You need to add approvalIds to the Rest API URL then the API can run successfully.

    For example:

    GET https://dev.azure.com/{organization}/{project}/_apis/pipelines/approvals?approvalIds={approvalIds}&api-version=7.1-preview.1
    

    To get the approvalid, you can use the Rest API: Timeline – Get

    GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline?api-version=6.0
    

    You can get the approvalid in the response.

    enter image description here

    The above call should, according to the documentation list all the approvals,

    From your requirement, you need to list all approvals in the project. I am afraid that the Rest API not able to meet your requirement for the time being.

    It only supports to return the Approvals defined in the Rest API URL.

    Currently, this API is still in the preview status, and some functions may not be perfected.

    You can refer to and monitor this feedback ticket with the same question: https://github.com/MicrosoftDocs/vsts-rest-api-specs/issues/557

    Login or Signup to reply.
  2. PowerShell example based on Kevin Lu-MSFT’s answer:

    $pat="<Your PAT>"
    $organization = "<Your Org>"
    $project = "<Your Project>"
    $buildId="123"
    $B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$pat"))
    $headers = @{ "Authorization" = "Basic $B64Pat"; "Accept" = "application/json"; "Content-Type" = "application/json" }
    $response = Invoke-WebRequest -Uri "https://dev.azure.com/$organization/$project/_apis/build/builds/$buildId/timeline?api-version=6.0" -Method GET -Headers $headers
    $buildTimeline = $response.Content | ConvertFrom-Json
    foreach($record in $buildTimeline.records){
        if ($record.type -eq "Checkpoint.Approval") {
            $approvalId = $record.id
            $response = Invoke-WebRequest -Uri "https://dev.azure.com/$organization/$project/_apis/pipelines/approvals?approvalIds=$approvalId&api-version=7.1-preview.1" -Method GET -Headers $headers
            $approval = $response.Content | ConvertFrom-Json
            Write-Host "ApprovalID=$approvalId and status=$($approval.value[0].status)"
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search