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.\r\nParameter 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.
I can reproduce the same issue.
The cause of the issue is that the format: $body | ConvertTo-Json
will not add the [] in the request body.
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.