In my post about the When a file is deleted trigger in Microsoft Flow I described the trigger that will fire when a document is deleted.

When a file is deleted

The trigger however will be quite useless if you want to do anything as there isn’t much information available within the information returned. One of my followers asked todayon the post mentioned above if it was possible to email the author when someone deletes document.

Deleted File

But no need to panic!

As so often the Send an HTTP  request to SharePoint action will come to the rescue.Get Reycle bin content with HTTP request using the REST API

The /api/web/RecycleBin REST API will give you all the documents that were deleted.

Then you can add a filter so that only the documents with the same file name are returned. In a similar way you could also include the Time deleted as a filter. But I would like to keep the example in this post simple.Send Email For Deleted File

To get the email address for the author’s email address the following expression will get the job done:

first(body('Send_an_HTTP_request_to_SharePoint')?['d']?['results'])['AuthorEmail']

Avatar for Pieter Veenstra

By Pieter Veenstra

Business Applications Microsoft MVP working as the Head of Power Platform at Vantage 365. You can contact me using contact@sharepains.com

17 thoughts on “Inform authors when a document is deleted from SharePoint with Microsoft Flow”
  1. Thank you very much for your prompt help!
    I got both issues, language issues (that’s why I was not searching the net for “author”) and reading codes: Could you explain the last part of your formula: first(body(‘HTTP-Anforderung_an_SharePoint_senden’)?[‘d’]?[‘results’])[‘AuthorEmail’]
    I do not get the authorEmail, Flow tells me, that the value AuthorEmail can not be selected. I have tried that with “Author”, as this is the column’s name, but this does not work either.

    1. Hi Johannes,

      Can you email the output from the HTTP request action to contact@veenstra.me.uk? Most likely, there is something not right there.
      In my case I get the following:

      {
      "d": {
      "results": [
      {
      "__metadata": {
      "id": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'582be79c-57a1-4d2c-bdc0-cecdc3e00a71')",
      "uri": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'582be79c-57a1-4d2c-bdc0-cecdc3e00a71')",
      "type": "SP.RecycleBinItem"
      },
      "Author": {
      "__deferred": {
      "uri": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'582be79c-57a1-4d2c-bdc0-cecdc3e00a71')/Author"
      }
      },
      "DeletedBy": {
      "__deferred": {
      "uri": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'582be79c-57a1-4d2c-bdc0-cecdc3e00a71')/DeletedBy"
      }
      },
      "AuthorEmail": "pieter@PieterVeenstraMVP.onmicrosoft.com",
      "AuthorName": "Pieter Veenstra",
      "DeletedByEmail": "pieter@PieterVeenstraMVP.onmicrosoft.com",
      "DeletedByName": "Pieter Veenstra",
      "DeletedDate": "2019-05-08T15:54:35Z",
      "DeletedDateLocalFormatted": "08/05/2019 16:54",
      "DirName": "Shared Documents",
      "DirNamePath": {
      "__metadata": {
      "type": "SP.ResourcePath"
      },
      "DecodedUrl": "Shared Documents"
      },
      "Id": "582be79c-57a1-4d2c-bdc0-cecdc3e00a71",
      "ItemState": 1,
      "ItemType": 1,
      "LeafName": "Document.docx",
      "LeafNamePath": {
      "__metadata": {
      "type": "SP.ResourcePath"
      },
      "DecodedUrl": "Document.docx"
      },
      "Size": "127810",
      "Title": "Document.docx"
      },
      {
      "__metadata": {
      "id": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'325a1cee-99fd-4ff3-9538-c7ad66166c55')",
      "uri": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'325a1cee-99fd-4ff3-9538-c7ad66166c55')",
      "type": "SP.RecycleBinItem"
      },
      "Author": {
      "__deferred": {
      "uri": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'325a1cee-99fd-4ff3-9538-c7ad66166c55')/Author"
      }
      },
      "DeletedBy": {
      "__deferred": {
      "uri": "https://pieterveenstramvp.sharepoint.com/_api/Web/RecycleBin(guid'325a1cee-99fd-4ff3-9538-c7ad66166c55')/DeletedBy"
      }
      },
      "AuthorEmail": "testuser@PieterVeenstraMVP.onmicrosoft.com",
      "AuthorName": "Test User",
      "DeletedByEmail": "pieter@PieterVeenstraMVP.onmicrosoft.com",
      "DeletedByName": "Pieter Veenstra",
      "DeletedDate": "2019-07-01T09:41:20Z",
      "DeletedDateLocalFormatted": "01/07/2019 10:41",
      "DirName": "Shared Documents",
      "DirNamePath": {
      "__metadata": {
      "type": "SP.ResourcePath"
      },
      "DecodedUrl": "Shared Documents"
      },
      "Id": "325a1cee-99fd-4ff3-9538-c7ad66166c55",
      "ItemState": 1,
      "ItemType": 1,
      "LeafName": "Document.docx",
      "LeafNamePath": {
      "__metadata": {
      "type": "SP.ResourcePath"
      },
      "DecodedUrl": "Document.docx"
      },
      "Size": "55640",
      "Title": "Document.docx"
      }
      ]
      }
      }

  2. I also get the same error…:/
    It seems like AuthorEmail is not an accepted term.

    InvalidTemplate. Unable to process template language expressions in action ‘Send_an_email’ inputs at line ‘1’ and column ‘2642’: ‘The template language expression ‘first(body(‘Send_an_HTTP_request_to_SharePoint’)?[‘d’]?[‘results’])[‘AuthorEmail’]’ cannot be evaluated because property ‘AuthorEmail’ cannot be selected.

    Thoughts?

      1. I don’t think that’s the problem.
        Looking in my failed flow, under send the ‘http request’ section, the URI value is coming back empty.
        /_api/web/RecycleBin?$filter=LeafName eq ”
        For some reason the ‘filename with extension’ is NOT producing complete api call.
        /_api/web/RecycleBin?$filter=LeafName eq ‘@{triggerBody()?[‘FileNameWithExtension’]}’

        If it can’t find the file it can’t match an author to send a delete message.

        Thoughts?

  3. Hi Pieter,

    thanks for this, i have tried it but got similar error for Author Email,
    InvalidTemplate. Unable to process template language expressions in action ‘Send_an_email’ inputs at line ‘1’ and column ‘2662’: ‘The template language expression ‘first(body(‘Send_an_HTTP_request_to_SharePoint’)?[‘d’]?[‘results’])[‘AuthorEmail’]’ cannot be evaluated because property ‘AuthorEmail’ cannot be selected. Please see https://aka.ms/logicexpressions for usage details.’.

    I verify when i add ; my email i can receive email notification but the Author Email not getting detected! if you can help

    1. Can you create a compose action that is set to

      first(body(‘Send_an_HTTP_request_to_SharePoint’)?[‘d’]?[‘results’])

      What does this return? If nothing is returned, then try the following in a compose:

      body(‘Send_an_HTTP_request_to_SharePoint’)?[‘d’]?[‘results’]

      1. can you please guide how to try in Compose? do you mean in new flow to create from blank as i tried but its not opened..

      2. Just inside your existing flow you can add a compose. The sole purpose of this compose will be debugging. Most likely the problem that you are hitting is about not getting the data in the shape that you expect it to arrive. This compose action will help us understand the data.

        So simply add an action. Select the compose action and then past part of the full expression. Then in run time you can see what happens.

  4. Hi Peter,

    I am trying to update the folder properties whenever file has been deleted.

    My use case:
    i have two folders, subfolder i have one files. whenever i am uploading new files, updating sub folder column(I have status column , update status column as Completed)

    Same way whenever i am trying to delete update status column is In progress.

    I am using same API. but unable to update

    /_api/web/RecycleBin?$filter=LeafName eq ‘@{triggerBody()?[‘FileNameWithExtension’]}’

    1. Do I understand it correctly that you are trying to update the folder that contains a documents that was deleted?

      That sounds like you would need the original location of the file that was deleted rather than the recycle bin location. I’m not sure if that is possible.

  5. Pieter, this is all very interesting. I wonder if there is a way to access the complete set of values of the deleted item (assuming it is a SharePoint list item, for example). After all, the item can be restored from the Recycle Bin, so its values are still encapsulated within and not yet lost forever at this stage. Yet the REST call only retrieves very limited data about the item (its ID and title) and the rest is metadata related to the deletion itself (deleted by, deleted date).

    I’m keeping a running count of some monetary value of items in a SharePoint list, and it would be helpful for me to access the value of an item at the time of its deletion, so I can decrement my running count accordingly.

    1. Hi Thomas,

      I have wondered many time why it is not possible to get to the data. When you look at the recycle bin in SharePoint you will also find that there is no data available about the documents/list items until you restore them. The data must still be stored in the SharePoint Database however this is not available through an API of any kind as far as I am aware.

      If you want to keep track of deleted item values then you will probably end up keeping a shadow list holding a copy of the original list. So that when items are deleted you can get to the data in the shadow list.

      1. Hi Peter, thank you for your quick reply. It will remain a mystery for now! Your idea of a shadow list also makes sense. Thanks!

  6. Hello,

    I have the needs. Are you sure about the uri. It returns nothing to me.
    If i try /_api/site/RecycleBin, i have a lot of data….but if i use your expression it send a mail to the first person who deleted the first file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SharePains by Microsoft MVP Pieter Veenstra

Subscribe now to keep reading and get access to the full archive.

Continue reading