How to remove permissions from a SharePoint folder with Power Automate

“I’d like to set unique permissions on a SharePoint folder I just created with Power Automate, but the ‘Stop sharing…’ action throws an error.”

“Folder is not supported for this operation.”


Power Automate has an action ‘Stop sharing an item or a file’ in SharePoint that will remove all permissions. It’s easy to manage permissions with this action, but only if you work with files or items. If you need to set permissions on a SharePoint folder, e.g. to create private folders, the action won’t help. It’ll just throw an error and stop the flow: “Folder is not supported for this operation.”.

Stop sharing SP folder in PA

How do you then remove the existing folder permissions to assign new ones?

Remove folder permissions with HTTP request

You’ll have to go back to the permissions management with HTTP requests. There’re three HTTP requests you’ll need to remove the permissions.

Note: all the code snippets below contain placeholders inside < … >, replace them including the < and >.

1. Break permissions inheritance

The first step is to break inheritance of the default permissions. Until you break the inheritance you can’t change any permissions as they’re managed on higher level than the folder.

Method: POST

Uri:
_api/web/lists/getByTitle('<LibraryName>')/items(<FolderID>)/breakroleinheritance(true)
Power Automate break permissions

2. List all users with permissions

The second step is to get all the permissions on the folder. The HTTP request in the 3rd step will need to know whose permissions it should remove, therefore, it’s necessary to get a list of all these users.

Method: POST

Uri:
_api/web/lists/getByTitle('<LibraryName>')/items(<FolderID>)/roleassignments
Power Automate list all users with permissions

The output of this request will be a JSON with ‘PrincipalId’ of all the users with access to the folder. Add the ‘Parse JSON’ action with schema from the output to get the ‘PrincipalId’ dynamic content for the step 3.

3. Remove all permissions

The last step is to remove the permissions. Here you’ll use the ‘PrincipalId’ to remove all the existing permissions from the folder. Since there can be multiple users with access to the item, Power Automate will add the ‘Apply to each’ around it automatically.

Method: POST

Uri:
_api/web/lists/getByTitle('<LibraryName>')/items(<FolderID>)/roleassignments(<PrincipalId>)

Headers:
X-HTTP-Method : DELETE
remove permissions from a SharePoint folder with Power Automate

After the ‘Apply to each’ the folder permissions will be empty and you can start adding the permissions you need. And this time you can use the ‘Grant access to an item or a folder’ action.

Summary

It’s sad that Power Automate doesn’t allow you to remove SharePoint folder permissions in the same way as from an item or a file. But as most of the other times, there’s a workaround with a bit of coding knowledge.

When you run the flow above, the only users with access to the folder will be the SharePoint site owners. All the other users, including the users with full control, must be then added back.

And if you’d like to get fancy, you could process the response from step 2 without the ‘Parse JSON’.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *