Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

How to remove permissions from a SharePoint folder with Power Automate

Posted on May 5, 2021March 20, 2022 by Tom

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


🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

37 thoughts on “How to remove permissions from a SharePoint folder with Power Automate”

  1. Dave says:
    October 26, 2021 at 1:45 am

    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.

    Reply
    1. Tom says:
      October 29, 2021 at 9:21 am

      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()

      Reply
      1. Bob says:
        August 19, 2022 at 2:01 pm

        Thats really helpful – thanks!
        I noticed the people who have been removed from the list/library can still access the site, any suggestions for that?

        Reply
        1. Tom says:
          August 28, 2022 at 7:19 pm

          Hello Bob,
          the article is on removing them only from a specific folder, not from the whole site. There might be some HTTP request to remove them from the site but I don’t know what it’d look like atm.

          Reply
    2. Hari says:
      September 3, 2024 at 8:18 am

      It worked for me but i have done some small changes while getting role assignments and while removing permissions.
      To get role assignments i have used the below uri:
      _api/web/lists/getByTitle(‘document libaray name’)/items(275)/roleassignments?$expand=Member,RoleDefinitionBindings
      To remove folder permission uri:
      _api/web/lists/getByTitle(‘Document library name’)/items(275)/roleassignments/removeroleassignment(principalid=, roledefid=)

      Reply
  2. Caspar says:
    January 30, 2022 at 7:39 pm

    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…

    Reply
    1. Caspar says:
      January 30, 2022 at 9:26 pm

      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…

      Reply
      1. Tom says:
        February 2, 2022 at 4:02 pm

        Hello Caspar,
        good to know, thank you for sharing your solution.

        Reply
      2. Max says:
        October 4, 2022 at 4:48 pm

        Could you please help! to remove the access to a folder?

        Reply
  3. Raj says:
    April 14, 2022 at 4:37 am

    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
    }
    }

    Reply
    1. Tom says:
      April 23, 2022 at 8:24 pm

      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.

      Reply
      1. Erik says:
        June 10, 2023 at 4:32 pm

        Could you elaborate on this? I’m having the same issue as Raj my Parse JSON output is below

        {
        …long json schema…
        }

        Reply
        1. Erik says:
          June 10, 2023 at 4:35 pm

          Sorry for posting the Schema, my JSON output is below

          {
          “d”: {
          “results”: [
          {
          “__metadata”: {
          “id”: “/_api/Web/Lists(guid’43129d07-f467-4dda-bcd7-1bc9787220fa’)/Items(7)/RoleAssignments/GetByPrincipalId(3630)”,
          “uri”: “/_api/Web/Lists(guid’43129d07-f467-4dda-bcd7-1bc9787220fa’)/Items(7)/RoleAssignments/GetByPrincipalId(3630)”,
          “type”: “SP.RoleAssignment”
          },
          “Member”: {
          “__deferred”: {
          “uri”: “/_api/Web/Lists(guid’43129d07-f467-4dda-bcd7-1bc9787220fa’)/Items(7)/RoleAssignments/GetByPrincipalId(3630)/Member”
          }
          },
          “RoleDefinitionBindings”: {
          “__deferred”: {
          “uri”: “/_api/Web/Lists(guid’43129d07-f467-4dda-bcd7-1bc9787220fa’)/Items(7)/RoleAssignments/GetByPrincipalId(3630)/RoleDefinitionBindings”
          }
          },
          “PrincipalId”: 3630
          },
          …
          ]
          }
          }

          Reply
          1. Tom says:
            August 12, 2023 at 10:57 pm

            Hello Erik,
            the output looks fine, just make sure your Parse JSON is properly configured.

  4. Nico says:
    June 9, 2022 at 8:50 am

    Hello Tom!
    I’ve setup a flow like this and most of the time it works fine, however sometimes I get an error in the apply to each step -> “Can not find the principal with id: xx.”

    When I restart the workflow manually, it usually works on the 2nd or 3rd attempt, however this is not really great since sometimes folder permissions are wrong until a flow run is successful.

    Do you know this issue and maybe even a solution?
    Thank you very much!

    Reply
    1. Tom says:
      June 19, 2022 at 9:31 am

      Hello Nico,
      I never encountered this, maybe there’re users who have assigned permissions through different group? I’d check the output of the /roleassignments HTTP request to check if there aren’t any duplicate principalIds.

      Reply
  5. Martin says:
    June 10, 2022 at 5:20 pm

    Hi Tom.. Excellent post. I have a slightly different requirement.

    First, the security groups always change name and we can assume sharing links are used.
    I need to keep only the owners full access access to the folder and modify all other users to have read only. I have tried polling users, groups and roleassignment to no avail.

    Any suggestions would be appreciated !

    Reply
    1. Tom says:
      June 19, 2022 at 9:37 am

      Hello Martin,
      you could list all permissions using /roleassignments, loop through the permissions and for each of them remove the current permission and add read instead. That way you’ll reduce everyone’s permissions to Read only. After that’s finished you can add Full Control back to the Owners group (which is hopefully the same every time).

      Reply
  6. nand says:
    July 6, 2022 at 1:04 am

    if anyone of you has this flow created (Revoke permission at folder level) please reply to this message, tried everything and I’m frustrated. or mail me at nnandan@oceaneering.com.
    Thank you so much in advance

    Reply
  7. Luuk T. says:
    October 10, 2022 at 11:48 am

    Hi Tom,

    Is it possible set unique permissions on subfolder level?

    Instead of “Site/Library/Folder” i want to create unique permissions on this level: “Site/Library/Folder/Subfolder”.

    I tried to change this URL:
    _api/web/lists/getByTitle(”)/items()/breakroleinheritance(true)

    To:
    _api/web/lists/getByTitle(”)/items()/items()/breakroleinheritance(true)

    But that did not work.

    I really appreciate your time.

    With kind regards, Luuk T.

    Reply
    1. Tom says:
      October 14, 2022 at 10:30 am

      Hello Luuk,
      you should be able to do that if you enter the subfolder id.
      _api/web/lists/getByTitle(listName)/items(subfolderID)/breakroleinheritance(true)

      Reply
  8. John says:
    February 2, 2023 at 3:52 am

    Hi Tom,

    Thanks for the Excellent post,

    I/m having an issue removing unique permission from folders an all the sub folders and files under.

    _api/web/lists/getByTitle(‘Document library’)/items(folder ID)/ResetRoleInheritance()

    above Uri only remove unique permission on a particular folder only.

    do you know how can i remove all the sub folder and files under the root folder?

    Thanks in advance

    Reply
    1. Tom says:
      February 9, 2023 at 10:00 pm

      Hello John,
      if there’s no inheritance to the folder and each subfolder/file in that folder have their own unique permissions then you must process them one by one, folder by folder. It’s the same as if you wanted to restore the permissions manually.

      Reply
  9. Anish says:
    February 23, 2023 at 12:29 pm

    Hi,
    I need to delete files from folders and subfolders which are older than 4years can you please help. These files have a lot of unique permissions can we remove permissions only for the deleting file and not for the rest?

    Thanks in advance.

    Reply
    1. Tom says:
      March 1, 2023 at 11:03 pm

      Hello Anish,
      you don’t care about permissions when you delete a file. As long as you have access to the file you can just delete it, no matter the permissions.

      Reply
  10. Amanda Oliva says:
    March 22, 2023 at 3:44 pm

    Thanks for this incredibly helpful resource. My workflow succeeded using the steps above but the Owners group was removed as well. I can probably just run another send HTTP request action to add them back but it shouldn’t have removed the Owners group on the folder, correct?

    Reply
    1. Tom says:
      April 2, 2023 at 11:45 am

      Hello Amanda,
      the HTTP requests will remove all groups, it’s the dedicated ‘Stop sharing…’ action (that can’t be used on folders) that keeps the owners.

      Reply
  11. Vasco says:
    July 5, 2023 at 3:40 pm

    Hi Tom. First of all, thank you for the amazing resource.

    I’ve done it all but when i check the acess it still have the group access.
    My goal was to remove the visitors and members of the channel (folder) so the owner (creator) can add the person and know one else have acess.

    Is this possible?
    Thanks!

    Reply
    1. Tom says:
      August 12, 2023 at 11:27 pm

      Hello Vasco,
      that was the goal of the solution, did you follow all the steps? It should remove all permissions – users, groups, even the owners.

      Reply
  12. Shamantha says:
    July 21, 2023 at 1:02 am

    I tried this , but it is deleting my folder in SharePoint, instead of removing the role permissions. Any idea on that?

    Reply
  13. Daniel Dumaresq says:
    July 26, 2023 at 7:27 pm

    Thank you so much! It works!

    Reply
  14. Paul CJ says:
    September 28, 2023 at 1:02 pm

    Thanks for the article and clear presentation.

    I found a problem removing the SPO groups’ permission, and a solution which looked at removing the specific role assignment in a similar fashion via the HTTP request:

    _api/web/lists/getbytitle(”)/items()/RoleAssignments/RemoveRoleAssignment(principalId=)

    where the is the variable supplied by the loop in which you return the assigned principals. My use case created a folder within the flow and thus came with the inherited groups pre-assigned. With this REST query I was able to strip those out effectively.

    Reply
    1. Tom says:
      October 22, 2023 at 3:53 pm

      Hello Paul,
      thank you for sharing this, although it seems wordpress replaced some characters from the response.

      Reply
  15. Ben says:
    April 29, 2024 at 6:08 pm

    Hi Tom,

    Thanks for this, really useful and well-explained guide.

    Unfortunately, I too am getting the error in the Apply to each at the last stage.

    ExpressionEvaluationFailed. The execution of template action ‘Apply_to_each’ failed: the result of the evaluation of ‘foreach’ expression ‘@body(‘Parse_JSON’)?[‘body’]?[‘d’]?[‘results’]’ is of type ‘Null’. The result must be a valid array.

    I’ve checked my roleassignments HTTP request, which seems to output very similar to yours.

    {
    “d”: {
    “results”: [
    {
    “__metadata”: {
    “id”: “/_api/Web/Lists(guid’002a002a-acbb-4b12-b52d-cc00f9ca5ce9′)/Items(124)/RoleAssignments/GetByPrincipalId(3)”,
    “uri”: “/_api/Web/Lists(guid’002a002a-acbb-4b12-b52d-cc00f9ca5ce9′)/Items(124)/RoleAssignments/GetByPrincipalId(3)”,
    “type”: “SP.RoleAssignment”
    },
    “Member”: {
    “__deferred”: {
    “uri”: “/_api/Web/Lists(guid’002a002a-acbb-4b12-b52d-cc00f9ca5ce9′)/Items(124)/RoleAssignments/GetByPrincipalId(3)/Member”
    }
    },
    “RoleDefinitionBindings”: {
    “__deferred”: {
    “uri”: “/_api/Web/Lists(guid’002a002a-acbb-4b12-b52d-cc00f9ca5ce9′)/Items(124)/RoleAssignments/GetByPrincipalId(3)/RoleDefinitionBindings”
    }
    },
    “PrincipalId”: 3

    [plus a few more]

    Interestingly, where you have the Site field in the ‘Apply to each’ HTTP Request item, yours shows a function outputs(..) whereas I have to set the Site to be as you would expect, my site.

    Any suggestions? Thanks.
    Ben

    Reply
  16. Melinda (Mel) Grant says:
    June 7, 2024 at 7:38 am

    Thanks for your clear instructions, but I can’t get it to work. I think this is because I’m trying to change a Document Set, rather than a file or folder. When someone adds/edits a Document Set, I want a condition checked on one of the columns. If it’s true, I need inheritance to be stopped and apply permission only to a couple of people.
    When I try your initial Uri, I get a 400 error with the message: “The expression \”web/lists/getByTitle(‘My Document Sets’)/items({\”@odata.etag\”:\”/\”12/\”\”,\”ItemInternalId\”:\”2\”,\”ID\”:2,\”Title\”:\”XYZ\”,\”Created\”:\”2024-05-13T05:29:36Z\”,\”Owner\”:[{\”@odata.type\”:\”\” is not valid.\r\nclientRequestId: 49869c78-bc95-4dfc-be90-840527ca4344\r\nserviceRequestId: bb3530a1-20e0-3000-6835-47ad5a96c33a”,

    Reply
  17. Shane says:
    November 7, 2024 at 2:27 am

    Tom,

    Thank you for this! Helps greatly.

    Do you know how to remove certain users instead of all? Currently trying to remove 5 specific users from multiple folder in a single Library with same name but keep the unique permissions for the remainder users.

    Reply
  18. Pingback: Power Automate: Créer une structure de dossiers avec une sécurite | KTNN SharePoint

Leave a Reply Cancel reply

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

🚀 Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundle—everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes