Can we manage deleted files in sharepoint using MS Graph API?

Aman Singh 31 Reputation points
2022-02-17T13:38:04.57+00:00

Hi,

Is there a way to manage deleted files/folders in sharepoint using MS Graph API or is there any other way to do it?

Functionalities like listing deleted files/folders, restoring them, permanently deleting them.

Hope for a quick response.

Thanks
Aman

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,021 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Rob Windsor 1,961 Reputation points
    2022-02-17T14:11:33.503+00:00

    Microsoft Graph does not support working with deleted files with one exception, you can restore deleted files in OneDrive Personal. You'll need to use the SharePoint Client Object Model or REST API if you want to work with the items/files in the recycle bin.

    Update:

    Here are some SharePoint REST API calls you can use:

    List recycle bin items: /_api/web/recyclebin
    Restore an item from the recycle bin: /_api/web/recyclebin('recyclebinitemid')/restore()
    Send an item to the recycle bin: /_api/web/lists/getbytitle('listname')/items(itemid)/recycle()

    Here are some links to general documentation on the SharePoint REST API.

    Get to know the SharePoint REST service
    Complete basic operations using SharePoint REST endpoints


  2. HarmeetSingh7172 4,811 Reputation points
    2022-02-17T18:20:21.08+00:00

    Hi @Aman Singh ,

    You can restore a driveItem (files/folders) that has been deleted and is currently in the recycle bin using the below API and this functionality is currently only available for OneDrive Personal. Delegated (personal Microsoft account) or "Application" permissions can be used. Please refer this restore drive item API documentation for more information.

    For listing deleted files/folders, you can use delta query as it enables applications to discover newly created, updated, or deleted driveItems. The initial request to the delta query function (no delta or skip token) will return the resources that currently exist in the collection. The final page of items will include the @odata.deltaLink property, which provides the URL that can be used later to retrieve changes since the current set of items.

    Endpoint-

    GET /sites/{siteId}/drive/root/delta  
    

    Please refer to below example screenshot:

    175525-driveitem2.png

    For deleting driveItem permanently from recycle bin, currently there is no Microsoft Graph API available.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have further questions about this answer, please click "Comment".

    0 comments No comments

  3. Aman Singh 31 Reputation points
    2022-02-18T06:46:40.59+00:00

    Hi @HarmeetSingh7172 ,

    Thanks for the response.

    I have tried this endpoint, I am able to get all files/folders for the root list of the site.

    https://graph.microsoft.com/v1.0/sites/######.sharepoint.com,######/drive/root/delta  
    

    But there is no attribute like "deleted" or "state" in the response and I don't see any files/folders from the recycle bin.

    Can you please help related to this ?


  4. Aman Singh 31 Reputation points
    2022-02-18T06:48:23.583+00:00

    Hi @Rob Windsor

    Thanks for the response.

    Can you please help me with some details on this Object Model and Rest API for sharepoint ?

    Regards
    Aman


  5. Aman Singh 31 Reputation points
    2022-03-01T03:53:42.093+00:00

    Hi @Rob Windsor @HarmeetSingh7172

    I have added a comment regarding my findings for the above discussion. I am getting some exception while running this sharepoint API and I am not able to move further because of that.

    Please take a look and let me know if something can be helpful here.

    Hope for a quick response.

    Regards
    Aman


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.