Home > Net >  Azure Devops REST API add reviewer to a PR
Azure Devops REST API add reviewer to a PR

Time:10-27

I need to add a reviwer to the PR. What I'm trying to do:

$url = "https://dev.azure.com/***/***/_apis/git/repositories/***/pullRequests/47108/reviewers/${reviwerID}?api-version=6.0"
Invoke-RestMethod -Uri $url -Method Post -Headers $AzureDevOpsAuthenicationHeader -ContentType application/json

Getting error: Invoke-RestMethod: {"$id":"1","innerException":null,"message":"Invalid argument value.\r\nParameter name: A valid reviewer must be supplied.","typeName":"Microsoft.TeamFoundation.SourceControl.WebServer.InvalidArgumentValueException, Microsoft.TeamFoundation.SourceControl.WebServer","typeKey":"InvalidArgumentValueException","errorCode":0,"eventId":0}

Where ${reviwerID} I tried to use an email/userPrincipalName and ID got from

az ad user show --id myemail

Nothing works fine except this command:

az repos pr reviewer add --id $myemail

But I need to use REST API, what I'm doing wrong?

CodePudding user response:

You can find ${reviwerID} through this request: Get Team Members With Extended Properties

$uriGetTeamMembers = "$orgUrl/_apis/projects/$teamProject/teams/$TeamName/members"
$teamMembers = Invoke-RestMethod -Uri $uriGetTeamMembers -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
$rvidentity = $teamMembers.value.Where({$_.identity.displayName -eq $rvname})
$rvidentity[0].identity.id
  • Related