“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.”.

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)

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

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

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. Unless it’s a SharePoint group, that one always needs an HTTP request.
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’.
Thanks for your post Tom, it’s pointed me in the right direction. I have the opposite issue where I’ve used the ‘Stop sharing an item or a file’ to remove a sharing link but because inheritance is still disabled on the file, I’ve reached the 50k unique permissions limit on the document library. Hopefully Microsoft support can help me restore the inheritance on the files I no longer need shared. Thanks again.
Hello Dave,
if you need to restore permissions inheritance then it’s doable using the ‘Send an HTTP request to SharePoint’ action.
Method: POST
Uri: _api/Web/lists/getByTitle('listName')/items(itemId)/ResetRoleInheritance()
Hey Tom, thanks for all your tutorials.
I’ve got an issue with this one, the remove permissions action actually deletes my folder somehow. So basically it does not remove the permissions but removes the whole folder on the first “apply to each” loop for the first PrincipalId. Any idea why this could happen?
The first action that doesn’t throw an error (the action that deletes the folder) has this
URI:_api/web/lists/getByTitle(‘CoFolders’)/items(29)/roleassignments(3)
and this Headers:
Key: X-HTTP-Method
Value: DELETE
the DocumentLibrary (CoFolders), Folder ID (29) and the UserID (3) are correct.
It just deletes the folder that I want to remove the Users Permissions…
Hmm nevermind, I got it to work by using the Uri: _api/web/GetFolderByServerRelativeUrl(‘CoFolders/@{triggerOutputs()?[‘body/Title’]}’)/ListItemAllFields/RoleAssignments/GetByPrincipalId(@{items(‘Apply_to_each_-_Remove_Permissions’)?[‘PrincipalId’]})
and using DELETE in the Method Field instead of POST and X-HTTP-Method, not sure why this one works for me but maybe it’s because of our strange development environment for power automate…
Hello Caspar,
good to know, thank you for sharing your solution.
in the apply to each I’m greeting below error
The execution of template action ‘Apply_to_each’ failed: the result of the evaluation of ‘foreach’ expression ‘@body(‘Parse_JSON’)?[‘d’]?[‘results’]’ is of type ‘Null’. The result must be a valid array.
and the Parse Json I’m getting
{
“d”: {
“BreakRoleInheritance”: null
}
}
Hello Raj,
the ‘Apply to each’ is processing outputs from the 2nd HTTP request that lists all the permissions, not the first one that just breaks the permissions.