0

I am looking for examples for updating work items in batches via the ADO REST APIs.

This document contains links for examples, which don't seem to work: https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/workitembatchupdate?view=azure-devops-rest-6.0

user1220169
  • 805
  • 2
  • 9
  • 14

1 Answers1

0

You can reference the old version document: Work Item Batch Update

Another way is writing a script to call the Work Items - Update REST API in a loop to update the work items based on you requirement.

Below is an example to update a specific work item using PowerShell for your reference:

Param(
   [string]$baseurl = "https://dev.azure.com/{organization}",  
   [string]$projectName = "Project",
   [string]$workitemid = "124",
   [string]$user = "user",
   [string]$token = "xxxxx PAT token here"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
write-host $WorkitemType

function CreateJsonBody
{

    $value = @"
[
  {
    "op": "test",
    "path": "/rev",
    "value": 2
  },
  {
    "op": "add",
    "path": "/fields/System.State",
    "value": "New"
  }

]

"@

 return $value
}

$json = CreateJsonBody

$uri = "$baseurl/$projectName/_apis/wit/workitems/$($workitemid)?api-version=6.0"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55