You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

是否存在可获取OneDrive回收站项目的Microsoft Graph API?

Can I retrieve a specified user's deleted OneDrive files via Microsoft Graph API?

Absolutely! Microsoft Graph provides dedicated endpoints to access the OneDrive Recycle Bin for a specific user. Here's everything you need to know:

Core Endpoint

To fetch all items in a target user's OneDrive Recycle Bin, use this GET request:

GET /users/{user-id}/drive/recycleBin

Replace {user-id} with the user's UPN (e.g., jane.smith@contoso.com) or their Azure AD object ID.

Required Permissions

The permissions you need depend on your authentication context:

  • Delegated permissions (user context):
    • Files.Read: Works if the authenticated user has explicit access to the target user's OneDrive
    • Files.Read.All: Grants access to any user's Recycle Bin (ideal for admin scenarios)
  • Application permissions (service context):
    • Files.Read.All: Required for service-to-service access to any user's Recycle Bin

Note: For delegated access, the authenticated user must have the necessary rights to view the target user's OneDrive (e.g., they're a global admin or have been granted direct access to the user's files).

Example Response Structure

The API returns a collection of deletedItem resources with key details like:

  • id: Unique identifier of the deleted item
  • name: Original file/folder name
  • deletedDateTime: Timestamp when the item was deleted
  • size: Item size in bytes
  • parentReference: Original location before deletion

Here's a simplified response snippet:

{
  "value": [
    {
      "id": "abc123xyz...",
      "name": "Q2_Marketing_Plan.pptx",
      "deletedDateTime": "2024-05-20T14:45:00Z",
      "size": 245000,
      "parentReference": {
        "path": "/drive/root:/Documents/Marketing"
      }
    }
  ]
}

Advanced Querying Options

Use OData parameters to refine your results:

  • Fetch specific fields with $select: GET /users/{user-id}/drive/recycleBin?$select=name,deletedDateTime
  • Filter items by deletion date with $filter: GET /users/{user-id}/drive/recycleBin?$filter=deletedDateTime gt 2024-05-01T00:00:00Z
  • Sort results with $orderby: GET /users/{user-id}/drive/recycleBin?$orderby=deletedDateTime desc

Key Notes

  • Recycle Bin items are retained based on your organization's OneDrive retention policy. Once permanently deleted (manually or after the retention period), they can't be retrieved via this API.
  • You can restore deleted items using the POST /users/{user-id}/drive/recycleBin/{item-id}/restore endpoint if needed.

内容的提问来源于stack exchange,提问作者user2862775

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:57:25