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

Announcements

News and Announcements icon
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
    310 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 412

#2
Vish WR Profile Picture

Vish WR 305

#3
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

Last 30 days Overall leaderboard