通过Microsoft Graph API检索SharePoint Online对象权限

时间:2019-03-18 19:02:28

标签: microsoft-graph sharepoint-online

我需要映射所有SharePoint Online对象(网站,列表,列表项,附件,文件,文件夹)的权限。通过CSOM API似乎可以实现,但是在Microsoft Graph中找不到类似的东西。

以下查询成功retrieves a requested item

https://graph.microsoft.com/beta/sites/root/Lists/{List ID}/items/{item ID}/

但是以下查询未按预期返回权限:

https://graph.microsoft.com/beta/sites/root/Lists/{List ID}/items/{item ID}/permissions

我收到以下错误:

{
    "error": {
        "code": "BadRequest",
        "message": "Resource not found for the segment 'permissions'.",
        "innerError": {
            "request-id": "ab9f4cfe-f0e1-433b-9767-96d4b3e58c59",
            "date": "2019-03-18T18:52:21"
        }
    }
}  

以下查询也收到相同的错误:

https://graph.microsoft.com/beta/sites/root/Lists/{List ID}/permissions

一年前,有人问very similar question,答案是不可能。

现在有可能吗?如果是,那我在做什么错?

2 个答案:

答案 0 :(得分:1)

ListListItem资源文档都没有将permissions显示为有效的属性或关系。

如果List是文档库,则可以使用关联的DriveItem来查看其permission集合:

GET /v1.0/sites/root/lists/{list-id}/items/{item-id}/driveitem/permissions

例如,在Graph Explorer中执行/v1.0/sites/root/lists/eacf1ff2-7f98-4f71-963a-44e0cf35f608/items/4/driveitem/permissions将返回:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('root')/lists('eacf1ff2-7f98-4f71-963a-44e0cf35f608')/items('4')/driveItem/permissions",
  "value": [
    {
      "id": "VGVhbSBTaXRlIE93bmVycw",
      "roles": ["owner"],
      "grantedTo": {
        "user": {
          "displayName": "Team Site Owners"
        }
      },
      "inheritedFrom": {}
    },
    {
      "id": "VGVhbSBTaXRlIFZpc2l0b3Jz",
      "roles": ["read"],
      "grantedTo": {
        "user": {
          "displayName": "Team Site Visitors"
        }
      },
      "inheritedFrom": {}
    },
    {
      "id": "VGVhbSBTaXRlIE1lbWJlcnM",
      "roles": ["write"],
      "grantedTo": {
        "user": {
          "displayName": "Team Site Members"
        }
      },
      "inheritedFrom": {}
    },
    //...

答案 1 :(得分:0)

https://graph.microsoft.com/v1.0/sites/fa9c83ba-e4cb-43e7-b00d-cceb7a3a1ad4/lists/7b3815ab-5bd9-49f4-b99b-69bb8b7a62cf/items/1/driveitem/permissions

{
    "error": {
        "code": "invalidRequest",
        "message": "Cannot request driveItem for an item that is not in a document library",
        "innerError": {
            "date": "2021-03-02T07:46:28",
            "request-id": "ef9ca55a-74c0-4498-a040-2349ea03b2fe",
            "client-request-id": "29419c1b-b33e-ec2e-4ad4-b480779a86b2"
        }
    }
}