Removing Item Permission Using SharePoint Workflow And REST API

Introduction

In a previous article, we saw "Breaking Item Permission Inheritance Using SharePoint Workflow And REST API" but what if the existing permissions are applied to the item already?

Now, I’m going to use SharePoint REST APIs to read all roles and permissions and then remove all the existing permissions to replace them with the new permission levels. 

SharePoint Designer Workflow 2013 to remove item permissions

Step 1

Create the variable JSONRequestHeader as a dictionary for setting a service call header to get all roles and assignments to the item.

SharePoint

Step 2

Create the variable readRolesApiUrl as a string to set the service URL.

SharePoint

Step 3

Then, call the service to get all roles to the item.

SharePoint

Step 4

Read all responses from the result and set it to the AllRoles variable.

SharePoint

Step 5

Get all counts of the data in AllRoles variable to loop through all the roles assigned.

SharePoint

Step 6

Create the index variable as an integer and set it as 0.

SharePoint

Step 7

Create the variable JSONDeleteHeader as a dictionary to set as a header for deleting the service call.

SharePoint

Step 8

Create the loop that runs repeatedly while Index is less than countRoles.

SharePoint

Step 9

Get the individual item and then get the principle id to remove the permission.

SharePoint

Step 10

Create the RoleAssignment delete API URL using string builder.

SharePoint

Step 11

Call the service to delete the permission of the particular principle ID (Group or User ID).

SharePoint

Step 12

Increment the value of the index. The loop will continue repeatedly till the condition fails.

SharePoint

That's it. Your old permissions are deleted successfully. In the next article, we will see how to add new permissions to the current item.

References

https://msdn.microsoft.com/en-in/library/office/dn531432.aspx

Summary

In this article, we have explored how to remove all permissions of the item by using SharePoint Workflow 2013 and REST API.