I am trying to set the AssignedTo in a PowerShell script, using the REST API. The user already has a bunch of work items assigned, and has been in the system for several month. I have tried using the Displayname, email (same as upn), and the link to the identity. All gives the same result:
Invoke-WebRequest : {"$id":"1","customProperties":{"ReferenceName":"System.AssignedTo"},"innerException":null,"message":"The identity value '[email protected]' for field 'Assigned To' is an unknow n identity.","typeName":"Microsoft.TeamFoundation.WorkItemTracking.Server.WorkItemFieldInvalidException, Microsoft.TeamFoundation.WorkItemTracking.Server","typeKey":"WorkItemFieldInvalidExce
I use the following script:
$tfsToken = "MYPAT"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($tfsToken)"))
$defaultColletion = "default_Collection"
$project = "Agile"
$childID = "63573"
$identityUpn = "[email protected]"
$childuri = ("http://tfs:8080/tfs/" + $defaultColletion + "/" + $project + "/_apis/wit/workitems?ids=" + $childID + "&expand=relations&api-version=5.0")
$header = @{authorization = "Basic $token"}
$childresult = Invoke-WebRequest -Uri $childuri -Method Get -Headers $header -ContentType "application/json-patch+json"
$childObj = $childresult.Content | ConvertFrom-Json
$updUrl = ($childObj.value.url + "?api-version=5.0")
$ownerUpd = @{}
$ownerUpd.Add("path","/fields/System.AssignedTo")
$ownerUpd.Add("op","add")
$ownerUpd.Add("value",$identityUpn)
$json = ConvertTo-Json @($ownerUpd) -Depth 5
$result = Invoke-WebRequest -Uri $updUrl -Headers $header -Method Patch -Body $json -ContentType "application/json-patch+json"
You can set into System.AssignedTo exactly what you see in Assigned To field in work item: Display Name of a user. You can find example here Update an identity field by display name:
[
{
"op": "add",
"path": "/fields/System.AssignedTo",
"value": "Jamal Hartnett"
}
]
Additional examples:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With