通过 Azure DevOps 中的图形 API 设置库安全角色

Set Library security roles through the Graph API in Azure DevOps

如果之前有人回答过这个问题,我非常抱歉,但我通过搜索找不到任何东西。我正在尝试 add users to a library role 通过 Azure DevOps API,但是我正在努力寻找正确的端点来执行此操作。我相当确定需要使用图表 API。

实现此目标的正确终点是什么?

Set Library security roles through the Graph API in Azure DevOps

对于这个问题,你可以试试这个api:

PUT https://dev.azure.com/{org}/_apis/securityroles/scopes/distributedtask.library/roleassignments/resources/{resourceId}?api-version=5.1-preview

示例请求正文:

[{
    "userId": "123b6558-85d0-464f-b2a7-xxxxx",
    "roleName": "Creator"
}]

响应示例:

{
    "count": 1,
    "value": [
        {
            "identity": {
                "displayName": "[111]\Contributors",
                "id": "123b6558-85d0-464f-b2a7-xxxxx",
                "uniqueName": "[111]\Contributors"
            },
            "role": {
                "displayName": "Creator",
                "name": "Creator",
                "allowPermissions": 5,
                "denyPermissions": 0,
                "identifier": "distributedtask.library.Creator",
                "description": "Creator can create and view the library items.",
                "scope": "distributedtask.library"
            },
            "access": "assigned",
            "accessDisplayName": "Assigned"
        }
    ]
}

此 api 是通过在浏览器中按 F12 从网络中获取的。

另外,关于如何添加用户为项目组成员,可以参考这篇rest api