I want to use SharePoint REST API to get and operate the permission value of a specific folder in Shared Documents.

大坂 翔 141 Reputation points
2021-08-17T07:16:13.69+00:00

I want to use SharePoint REST API to get and operate the permission value of a specific folder in Shared Documents.

The SharePoint REST API docs had a site-wide role permission operation "https: // <servername> / site / _api / web / RoleAssignments", but there is no mention of the specific folder access operation I want to do this time. was.

How do I make an HTTP request to change the permissions on a particular folder?
If you are familiar with this, please answer.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,621 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,668 questions
SharePoint Workflow
SharePoint Workflow
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Workflow: An orchestrated and repeatable pattern of business activity, enabling data transformation, service provision, and information retrieval.
508 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,573 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 31,071 Reputation points Microsoft Vendor
    2021-08-18T06:42:49.737+00:00

    Hi @大坂 翔 ,
    First we need to break role inheritance for the folder.

    function breakRoleInheritanceOfFile() {   
    	 $.ajax({  
    			url: siteurl + String.format("/_api/web/GetFolderByServerRelativeUrl('DocumentTest/test999')/ListItemAllFields/breakroleinheritance(true)"),  
    			type: "POST",  
    			contentType: "application/json;odata=verbose",  
    			headers: {  
    				"Accept": "application/json;odata=verbose",  
    				"X-RequestDigest": $("#__REQUESTDIGEST").val()  
    			},  
    			success: onQuerySucceeded,  
    			error: onQueryFailed  
    	 });     
    }  
    

    Remove the current role assignment for the folder

    function remove(){  
    	$.ajax({  
    			url: siteurl + String.format("/_api/web/GetFolderByServerRelativeUrl('DocumentTest/test999')/ListItemAllFields/roleassignments/getbyprincipalid(11)"),  
    			method: "POST",  
    			headers: {  
    				   Authorization: "Bearer " + accessToken,  
    				   "accept": "application/json;odata=verbose",  
    				   "content-type": "application/json;odata=verbose",  
    				   "X-HTTP-Method": "DELETE"  
    			},  
    			success: onQuerySucceeded,  
    			error: onQueryFailed  
    	});   
    }  
    

    Add the new role assignment for the folder

    function add(){  
    	$.ajax({  
    			url: siteurl + String.format("/_api/web/GetFolderByServerRelativeUrl('DocumentTest/test999')/ListItemAllFields/roleassignments/addroleassignment(principalid=11,roledefid=1073741829)"),  
    			method: "POST",  
    			headers: {  
    				   Authorization: "Bearer " + accessToken,  
    				   "accept": "application/json;odata=verbose",  
    				   "content-type": "application/json;odata=verbose"  
    			},  
    			success: onQuerySucceeded,  
    			error: onQueryFailed  
    	}); 	  
    }  
    

    In order to use this API we need 'FullControl' permissions,So we need get Access Token by app


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful