我正在尝试使用Azure DevOps RestApi设置Azure DevOps组的项目权限。我尝试使用访问控制条目,但似乎不起作用。
$securityNamespaceId = "52d39943-cb85-4d7f-8fa8-c6baac873819"
$groupDesc = "vssgp.Uy0xLTktMTU1MTM3NDI0NS0yMzY2NjcwMjQwLTIyNDExNTQxMjQtMzEwMzY2MTYyNS0zODgxOTE3ODcxLTEtMzk0MjAxMzY5NS00MTY5ODI4NjEtMjk1MDY4ODE5MC0yMDI0NjY2NTQz"
$projectId = "12313142-eec0-4c3d-b9b5-44d0c3973b3e"
$token = "`$PROJECT:vstfs:///Classification/TeamProject/$($projectId)"
$allowMask = 4
$denyMask = 0
$bodyInfo = @{
token = $token
merge = $true
accessControlEntries = @{
descriptor = $groupDesc
allow = $allowMask
deny = $denyMask
Extendedinfo= {}
}
}| ConvertTo-Json
$uri = "https://dev.azure.com/<Organization>/_apis/accesscontrolentries/52d39943-cb85-4d7f-8fa8-c6baac873819?api-version=5.0"
Invoke-RestMethod -Method Post -Uri $uri -Body $bodyInfo -Headers $headers -ContentType "application/json"
Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred. Activity Id:
73da9e7f-1f9a-4d56-b8ca-f1e9e13513a6.","typeName":"Newtonsoft.Json.JsonSerializationException, Newtonsoft.Json","typeKey":"JsonSerializationException","errorCode":0,"eventId":0}
At line:1 char:1
+ Invoke-RestMethod -Method Post -Uri $uri -Body $bodyInfo -Headers $he ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
答案 0 :(得分:0)
错误表明无法将当前JSON对象(例如{“ name”:“ value”})反序列化为类型'System.Collections.Generic.List`1 [Microsoft.VisualStudio.Services.Security.AccessControlEntry]',因为类型需要JSON数组(例如[1,2,3])才能正确反序列化。
要解决此错误,可以将JSON更改为JSON数组(例如[1,2,3]),也可以更改反序列化类型,使其成为普通的.NET类型(例如,不是整数之类的原始类型,而不是可以从JSON对象反序列化的集合类型(如数组或List)。还可以将JsonObjectAttribute添加到类型中,以强制其从JSON对象反序列化。路径“ accessControlEntries.allow”。
此外,请确保您的PAT具有vso.security_manage范围。