web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to delete sharepoi...
Power Automate
Unanswered

How to delete sharepoint folder if name substring contains "EmailMessages" using Send HTTP

(0) ShareShare
ReportReport
Posted on by 6

Hi There!

I've dug through the forums and blogs and am coming up empty handed. I'm a beginner with power automate, so please bear with me.

 

I am feeding an emailed excel report to sharepoint on a daily basis. Sharepoint places the attached excel report into a folder that dynamically includes the month_year. I'm able to write a flow that renames and moves the attached excel file like I need, however I can't figure out how to write a flow that deletes the folder AFTER I've renamed & moved the excel report.

 

Example Folder I need to delete:

bROC_0-1700326699027.png

 

I've gleaned from the forum that I need to send a DELETE request to sharepoint via "Send an HTTP request to Sharepoint", however I'm unsure how to directly reference this dynamically changing folder that contains a certain substring "EmailMessages". The folder is located in the following directory: .../sites/TEST/Shared%20Documents/Analysis/EmailMessages_11_2023?csf=1&web=1&e=Cdtfcc

 

I believe I need to use: "Get files (properties only)" followed by "Send an HTTP request to Sharepoint" with Method DELETE, but don't know what URI to utilize, nor if I need to include any Headers or Body.

 

Could someone provide some guidance? 

Thanks so much!

Categories:
I have the same question (0)
  • Gdarmon Outlook Profile Picture
    372 on at

    Hi,

    To delete a SharePoint folder if the name substring contains “EmailMessages” using Send HTTP in Power Automate, you can use the following steps:

    1. Add the Get files (properties only) action to your flow.
    2. In the Site Address field, specify the URL of the SharePoint site that contains the folder.
    3. In the Library Name field, specify the name of the document library.
    4. In the Filter Query field, specify the filter query to retrieve the folder you want to delete.
    5. Add the Apply to each action to your flow and select the output of the Get files (properties only) action as the input.
    6. Add the Send an HTTP request to SharePoint action to your flow and specify the following:
      • In the Site Address field, specify the URL of the SharePoint site that contains the folder.
      • In the Method field, select DELETE.
      • In the Uri field, specify the URL of the folder you want to delete. You can use the following URI format: _api/web/GetFolderByServerRelativeUrl('<folder_url>'). Replace <folder_url> with the relative URL of the folder you want to delete.
      • In the Headers field, specify the following:
        • Content-Type: application/json;odata=verbose
        • Accept: application/json;odata=verbose
      • In the Body field, specify the following JSON payload: { "__metadata": { "type": "SP.Folder" }, "ServerRelativeUrl": "<folder_url>" }. Replace <folder_url> with the relative URL of the folder you want to delete.

    Once you have completed these steps, the folder that contains the substring “EmailMessages” will be deleted from the SharePoint site.

     

    Br,

    Gill

  • bROC Profile Picture
    6 on at

    Thank you so much for the explanation! I'm running into 2 issues related to the uri / JSON payload in the Send an HTTP request to sharepoint:

    1st question: When you're referring to <folder_url>, I'm not 100% sure I have the correct address. I believe this is only asking for the document library, correct? For example - The full url is https://xxxxxxx/sites/PJR%20Testing/Shared%20Documents/PCR%20Analysis.com. For this situ, my folder URL would be: "PCR Analysis"?

    2nd question: When I use "PCR Analysis" in that situation, I am receiving a error: 

    Access denied.
    clientRequestId: b4a662b4-0967-442f-a702-abb788524669

    serviceRequestId: 5152f0a0-e0a4-4000-61f6-3412f7cc19ae

    Any idea how I get around that?

    bROC_0-1700588699629.png

     

  • Verified answer
    Gdarmon Outlook Profile Picture
    372 on at

    Hi,

     

    When referring to a folder URL in SharePoint, it is usually the URL of the folder’s parent document library. In your example, the full URL is https://xxxxxxx/sites/PJR%20Testing/Shared%20Documents/PCR%20Analysis.com. The folder URL would be Shared Documents.

     

    this should resolve the issue.

    Gill

  • bROC Profile Picture
    6 on at

    Thanks again, Gill!

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard