• Ajith Madathil

How to remove a user sharing permission from a SharePoint Library folder?

By default SharePoint list and libraries inherit permissions from parent site. You can break the inheritance and create unique permissions on a particular list or library. Suppose you have a document library with multiple folders or files where you need to share specified files or folders to a particular user. In these scenario you need break the inheritance and use the share option to give permission to that particular user. In this article I will explain how to remove a user sharing permission from a specified SharePoint library folder using Power Automate (https://powerautomate.com).


Background


I have a document library named 'TestAjDocLib' and a folder called 'A1'. Custom permissions are set for this document library. Folder 'A1' is shared with a particular user. I want to remove this users shared permission from folder 'A1'.


Power Automate Build


There are no out of the box SharePoint connectors to do this job using Power Automate. The only option we have is to use the REST API method.


_api/web/GetFolderByServerRelativeUrl('TestAjDocLib/A1')/ListItemAllFields/RoleAssignments/GetByPrincipalId({User_Id'})


First we need to find the user principal id then execute the http DELETE post using the above SharePoint REST API. To find the user principal id here I am using the user email address.


Steps


REST API to get user principal id:

_api/web/siteusers/getbyEmail('user@email.com')


Next we need to use Parse JSON action step to extract the user principal id.



Following is the JSON schema I used above.


{ "type": "object", "properties": { "d": { "type": "object", "properties": { "__metadata": { "type": "object", "properties": { "id": { "type": "string" }, "uri": { "type": "string" }, "type": { "type": "string" } } }, "Alerts": { "type": "object", "properties": { "__deferred": { "type": "object", "properties": { "uri": { "type": "string" } } } } }, "Groups": { "type": "object", "properties": { "__deferred": { "type": "object", "properties": { "uri": { "type": "string" } } } } }, "Id": { "type": "integer" }, "IsHiddenInUI": { "type": "boolean" }, "LoginName": { "type": "string" }, "Title": { "type": "string" }, "PrincipalType": { "type": "integer" }, "Email": { "type": "string" }, "Expiration": { "type": "string" }, "IsEmailAuthenticationGuestUser": { "type": "boolean" }, "IsShareByEmailGuestUser": { "type": "boolean" }, "IsSiteAdmin": { "type": "boolean" }, "UserId": { "type": "object", "properties": { "__metadata": { "type": "object", "properties": { "type": { "type": "string" } } }, "NameId": { "type": "string" }, "NameIdIssuer": { "type": "string" } } }, "UserPrincipalName": { "type": "string" } } } } }


Finally use the below REST API step to remove the user permission from a particular folder.


Using the above method we can remove the users custom permission from a custom folder using Power Automate (aka Microsoft Flow).


Thanks for reading my post.

0 views
Blog Categories
 

Beginner

Intermediate

 

Advanced

Power Automate Essentials

How can I help you?

I am happy to help at any time.  You can contact me via the official PowerAutomate community forum.  Tag me (@abm) on any post you make there if you would like to me take a look at it.

I am always available for both corporate training or 1-2-1 training for individuals. 

© 2023 by Walkaway. Proudly created with Wix.com

  • Twitter Black Round
This site was designed with the
.com
website builder. Create your website today.
Start Now