skip to Main Content

I am trying to approve stages of a multi-stage yaml pipeline in azure devops but my REST requests to the endpoint detailed here return an error

{"$id":"1","innerException":null,"message":"Value cannot be null.rnParameter name: updateParameters","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}

I followed the strategy of obtaining the approval ID from the timeline of the pipeline (documented here), then getting the approval details (documented here), which gave me the 2 objects:

Approval stage from timeline

{
"previousAttempts":  [

                     ],
"id":  "e23aa595-7745-4015-9fdd-be7863faeda1",
"parentId":  "4ae2b754-452d-5a7c-1d05-4887a615523a",
"type":  "Checkpoint.Approval",
"name":  "Checkpoint.Approval",
"startTime":  "2023-11-15T12:36:50.5633333Z",
"finishTime":  null,
"currentOperation":  null,
"percentComplete":  null,
"state":  "inProgress",
"result":  null,
"resultCode":  null,
"changeId":  71,
"lastModified":  "0001-01-01T00:00:00",
"workerName":  null,
"details":  null,
"errorCount":  0,
"warningCount":  0,
"url":  null,
"log":  null,
"task":  null,
"attempt":  1,
"identifier":  "e23aa595-7745-4015-9fdd-be7863faeda1"
}

and approval direct from GET request

{
"id":  "e23aa595-7745-4015-9fdd-be7863faeda1",
"steps":  [

          ],
"status":  "pending",
"createdOn":  "2023-11-15T12:36:50.53Z",
"lastModifiedOn":  "2023-11-15T12:36:50.531529Z",
"executionOrder":  "anyOrder",
"minRequiredApprovers":  1,
"blockedApprovers":  [

                     ],
"_links":  {
               "self":  {
                            "href":  "https://dev.azure.com/<orgName>/8f6c8014-5c15-49aa-8efc-adb274f30be3/_apis/pipelines/approvals/e23aa595-7745-4015-9fdd-be7863faeda1"
                        }
           },
"pipeline":  {
                 "owner":  {
                               "_links":  "@{web=; self=}",
                               "id":  23633,
                               "name":  "20231115.7"
                           },
                 "id":  "64",
                 "name":  "Traveller"
             }
}

I then constructed the PATCH body

[
{
    "status":  "approved",
    "approvalId":  "e23aa595-7745-4015-9fdd-be7863faeda1",
    "comment":  ""
}
]

and sent this to the endpoint

https://dev.azure.com/<orgName>/<projectname>/_apis/pipelines/approvals?api-version=7.1-preview.

All documentation and other questions on this subject suggest I am doing this correctly, yet I cannot get past this error.

Other SO question consulted include
this and this

2

Answers


  1. I can reproduce the same issue.

    enter image description here

    The cause of the issue is that the format: $body | ConvertTo-Json will not add the [] in the request body.

    enter image description here

    To solve this issue, you can change to use the following format: ConvertTo-Json $body

    $response = Invoke-RestMethod -Method PATCH -Uri  $uri -Headers $headers  -Body ( ConvertTo-Json $body  ) -ContentType "application/json"
    

    Then it will pass the correct request body to the Request.

    Login or Signup to reply.
  2. I used the json contents directly to define the request body. Here is my sample for your reference.

    $organization = "Org"
    $project = "Project"
    $MyPat = 'xxxxx'
    $B64Pat = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$MyPat"))
    $URL = "https://dev.azure.com/$organization/$project/_apis/pipelines/approvals?api-version=7.1-preview.1"
    $header = @{
    'Authorization' = 'Basic ' + $B64Pat
    'Content-Type' = 'application/json'
    }
    $body = @"
    [
    {
        "status": "approved",
        "approvalId": "2c8f92ed-6c78-4ccb-8cb6-59afec19cec2",
        "comment": ""
    
    }
    ]
    "@
    
    $response = Invoke-RestMethod -Method PATCH -Uri $URL -Headers $header -Body $body | ConvertTo-Json
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search