Reputation:
What is the best way to get role definition id of the predefined role (like, reader, admin)?
I'm trying to configure a folder to have members have only read permissions. For this I'm removing existing role assignments to members and adding reader role to them. SharePoint REST API requires me to provide role definition id, but I can't find a way to get it reliably.
It seems like I can get it by name _api/web/roledefinitions/getbyname('Read')
, but I'm concerned how to handle the case of non-English locale. I would expect it can be searched by type kind _api/web/roledefinitions/getbytypekind(2)
, but I can't get it working. It gives me an error Cannot find resource for the request getbytypekind.
Also, can default role definition be deleted?
Upvotes: 2
Views: 5655
Reputation: 1874
You can get the role definition list by
https://xxxx.sharepoint.com/_api/Web/RoleDefinitions
Then you can get the specific role by id(like read),so we don't need to care the locale issue:
https://xxxx.sharepoint.com/_api/Web/RoleDefinitions(1073741826)
The role list and id:
FullControl(Web/RoleDefinitions(1073741829))
Design(Web/RoleDefinitions(1073741828))
Edit(Web/RoleDefinitions(1073741830))
Contribute(Web/RoleDefinitions(1073741827))
Read(Web/RoleDefinitions(1073741826))
Limited Access(Web/RoleDefinitions(1073741825))
System.LimitedView(Web/RoleDefinitions(1073741926))
System.LimitedEdit(Web/RoleDefinitions(1073741927))
Create new subsites(Web/RoleDefinitions(1073741924))
View Only(Web/RoleDefinitions(1073741925))
We can use the default role or customize our own role, so i think Microsoft do not need to provide API for deleting built-in roles.
Although we can use the getbytype method too, but the list of role type values are not very user friendly.(see more in the link below)
https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_RoleDefinitionCollectionGetById https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_RoleDefinitionCollectionGetByType
Upvotes: 0
Reputation: 59348
It seems like I can get it by name _api/web/roledefinitions/getbyname('Read'), but I'm concerned how to handle the case of non-English locale
that's correct, SP.RoleDefinition.name
property could vary per locale, so retrieving role definition by role type is definitely more reliable in this regard, SP.RoleDefinitionCollection.getByType
method could be utilized here, for example:
/_api/web/roledefinitions/getByType(<roletypeid>)
where roletypeid
corresponds to SP.RoleType
enumeration
Upvotes: 1