Forum Discussion
Azure DevOps REST API - tag DeploymentGroups' target
- Jun 19, 2025
I found the solution to the problem. In fact while using the ConvertTo-Json command onto the $body object, the formatting wasn't correct for the API. When I have a single target to update, the JSON doesn't show as an array so to enforce it I had to add the Switch parameter -AsArray to the convertTo-Json command. Doing so, the json payload is correctly formatted to PATCH the targets with the API.
So the solution is really to make sure the json payload starts as an Array containing Objects with the target ID and the list of tags as an array. Bellow the fixed command.
Invoke-RestMethod -Method Patch -Uri "$baseurl/distributedtask/deploymentgroups/$($DGid)/targets?api-version=6.0-preview.1" -Credential $cred -Body ($body | ConvertTo-Json -asArray) -ContentType 'Application/json'
And make sure the JSON is well in an Array like bellow :
[
{
"id": 541,
"tags": [
"tag1-backendWithDb",
"tag1-backendWithDb-active-node",
"tag2-backendWithDb-database",
"tag2-backendWithDb",
"tag2-backendWithDb-active-node",
"tag3-blazor",
"tag3-blazor-active-node",
"tag4-yarp",
"tag4-yarp-active-node"
]
}]
Try below to include the target machine ID:
{
"machinesToUpdate": [
{
"id": 541,
"tags": [
"tag1-backendWithDb",
"tag1-backendWithDb-active-node",
"tag2-backendWithDb-database",
"tag2-backendWithDb",
"tag2-backendWithDb-active-node",
"tag3-blazor",
"tag3-blazor-active-node",
"tag4-yarp",
"tag4-yarp-active-node"
]
}
]
}
Please also check API version compatibility
- AMDBauwensJun 10, 2025Copper Contributor
Thank you for your answer. This is a solution I tried already but did not work and get the exact same error. The maximum API version I can use is the 6.0. I consulted the document page of this version but I cannot say judging by the information on the page that there would be an incompatibility using this version.