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 / Using Send an HTTP req...
Power Automate
Answered

Using Send an HTTP request to SharePoint to delete a folder and its contents

(2) ShareShare
ReportReport
Posted on by 10
Hi,
 
I have been using "Send an HTTP request to SharePoint" with the below details to delete a folder and all of its contents in one action for over 9 months now. Two weeks ago, this started failing with message that the folder needs to be empty before it can be deleted. Any ideas/workarounds to make this operational again without having to delete all files in all subfolders prior to deleting the parent folder?
 
Current details (specific URIs replaced with generics):
Send an HTTP request to SharePoint
Site address: https://mysharepointsite.com/sites/SITENAME
Method: DELETE
Uri: _api/web/getFolderByServerRelativeUrl('/sites/SITENAME/Shared Documents/FolderName/DeleteThisFolder')

Headers:
  Prefer: bypass-shared-lock
 
Error returned:
"message": "BadGateway",
"status": 502,
"message": "You have to delete all the items in this folder before you can delete the folder..."
Categories:
I have the same question (0)
  • Verified answer
    Kameshm05 Profile Picture
    302 Moderator on at
    Hi,

    If the site is subject to a preservation-retention policy or an eDiscovery hold, we may encounter this error message. When a site is on hold, documents can be deleted, but folders containing files and sub-folders cannot be deleted directly. This is how the preservation hold mechanism works to prevent data loss.

    So please delete the files under the folders first and delete the folder. This is how we can fix this or you have to disable the policies on the site.

    If you want to delete the files under the folder follow this video. it will help you..
    https://www.youtube.com/watch?v=9UMtqt_1mpE

    Thanks
  • BD-06080258-0 Profile Picture
    10 on at
    Thank you!

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 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard