MicrosoftDocs / vsts-rest-api-specs

MIT License
166 stars 115 forks source link

Set project permissions for Azure DevOps groups in Azure DevOps #223

Open ghost opened 5 years ago

ghost commented 5 years ago

I am trying to set permissions of Azure DevOps project settings but having difficult time figuring out how to make it work.

$securityNamespaceId = "52d39943-cb85-4d7f-8fa8-c6baac873819"
$groupDesc = "vssgp.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$projectId = "123812837-9339-48383-4838-183948134" #random 

$allowMask = 4
$denyMask = 0

$bodyInfo = @{
                token = $token
                merge = $true
                accessControlEntries = @{
                        descriptor = $groupDesc
                        allow = $allowMask
                        deny = $denyMask
                        Extendedinfo=  {}               
                } 
}| ConvertTo-Json

$uri = "https://dev.azure.com/OrganizationName/_apis/accesscontrolentries/52d39943-cb85-4d7f-8fa8-c6baac873819?api-version=5.0"

Invoke-RestMethod -Method Post -Uri $uri -Body $bodyInfo -Headers $headers -ContentType "application/json" 

I am getting the following error message. Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id: f33cb608-a1fb-480f-a1f1-9d0db1f5fa7c.","typeName":"Newtonsoft.Json.JsonSerializationException, Newtonsoft.Json","typeKey":"JsonSerializationException","errorCode":0,"eventId":0} At line:4 char:1

FokkoVeegens commented 9 months ago

Late to the party, it's probably already solved, but maybe this helps others: You never set the $token variable. It should be set like this:

$token = "`$PROJECT:vstfs:///Classification/TeamProject/$($projectId)"

Furthermore, the accessControlEntries property is an array, so it should be enclosed in @() instead of @{}