In this post, we will see what is a Role Definition id, why it is needed and how to get it. Then we will see an example with the steps listed to create a custom permission in the site collection and get the role definition id for that.
What is Role Definition ID
In SharePoint, we are all familiar with SharePoint Permission and Permission levels like Full Control, Edit, and Contribute, etc. We use these permission levels to manage Site/List/item level accessibility. Sometimes, we create custom permission for business requirements. These permissions are being defined in the SharePoint with a unique id which is being called “SharePoint Role Definition ID”.
Why It Is Needed
In general, role definition ids’ are not needed to provide permission to a user or group in a Site, List or a List Item. We can do with OOB way as clicking some steps. But when we try to set permission by using REST Calls, we can’t use the permission level’s name. Then we need these Role Definition ID. As an example, if we try to change an user’s/group’s permission with rest call, it will be as follows:
How to Get Role Definition ID
So, now the question that comes in mind is, how to get these permission levels assigned Id or SharePoint Role Definition Id. For most of the common permission levels, we can get the Role Definition Id easily from the internet. Some out of the box role definition names (Permission level) and their corresponding role definition ids are given below:
|Role Definition Name ||Role Definition Id |
|Full Control ||1073741829 |
|Design ||1073741828 |
|Edit ||1073741830 |
|Contribute ||1073741827 |
|Read ||1073741826 |
|Limited Access ||1073741825 |
|View Only ||1073741924 |
But what about any custom permission level which is being created for some specific purpose in that site? Now step by step, we will walk through the process of how to get the SharePoint Custom Role Definition ID. To get the custom permission’s role definition ID, we have to use rest call. And with this rest call, we will also get the above out of the box role definition IDs.
Let’s create a custom permission in the site collection and get the role definition id for that as an example with the following steps:
First, go to the site settings of the site collection.
Click on Site Permissions. For Modern site, site permission option is available in the Settings option on the right corner of top menu bar as shown in the below image:
Figure 1: Site Permissions in Site Settings
Site permission window will open.
Click on the “Permission Levels” menu from the top menu as shown in the below image:
Figure 2: Permission Level Option in Site Permission Window
Permission levels window will be opened as like the following image.
We can get all the permission levels for this site collection, both out of the box and custom ones. We can also change the permission details of this role definition.
Figure 3: Permission Level Window
Now click on the “Add a permission Level” link as shown in the above image (figure 3).
This will open a new window to create new permission level as shown in the following image (figure 4).
Figure 4: New Permission Level Creation Page
Now, provide your custom permission’s name in the text box.
We can provide a description for future understanding.
Now we have an option for selecting different types of permissions which are being categorized with “List Permissions”, “Site Permissions” and “Personal Permissions”.
We need to check the needed permission as shown in the image (figure 4).
Click in the “Create” button.
Figure 5: The Custom Permission has been created
Now our custom permission level “
TestPermission” has been created as we can see in the above image.
Now, let’s get the role definition id of this custom permission level. To do that, we have to call the REST API which we already discussed before.
For me, the REST API URL is as follows:
This is a “
GET” request. So we can request this URL in our web browser. We will get the response in XML format where we can get all the Role Definitions and Role Definition ID.
For better visibility, we can use any online XML beautification tools or XML (XML to JSON Converter). Here is the result I got:
Figure 6: Response of the Rest Call
We can find our custom permission level as well as out of the box permission level’s role definition id and other details here.
So, for our custom permission level “
TestPermission”, the role definition id is “
So this is the way to find the SharePoint Role Definition IDs. In recent days, when SharePoint 2010 Workflows are going to be retired, we had to use SharePoint 2013 workflow or Microsoft power automation. In these procedures, we need these Role Definition IDs to set permission with REST call.
I hope this tip will help. Be safe. Happy coding!
- 11th October, 2020: Initial version