Skip to main content

How to Create a SharePoint Permission Level with the REST API in Power Automate

· 10 min read
Jagdish Kumawat
Founder @ Dewiride

SharePoint has no flow action that creates a permission level, but its REST API does: one POST to the site's role definitions, with the level's name, description and permissions. A flow can look for the level first, so it's created once however often the flow runs.

Syntax​

Both requests go through Send an HTTP request to SharePoint (How to Use Send an HTTP Request to SharePoint), with the header Accept: application/json;odata=nometadata. A permission level is a role definition in the REST API.

Look for the level​

FieldValue
MethodGET
Uri_api/web/roledefinitions?$filter=Name eq '<level name>'&$select=Id

The answer's value array holds the level's ID when it exists, and is empty when it doesn't.

Create the level​

FieldValue
MethodPOST
Uri_api/web/roledefinitions
HeadersContent-Type: application/json;odata=verbose, as well as Accept
Body: general form
{
"__metadata": { "type": "SP.RoleDefinition" },
"Name": "<level name>",
"Description": "<description>",
"BasePermissions": {
"__metadata": { "type": "SP.BasePermissions" },
"High": "<high>",
"Low": "<low>"
}
}
  • <level name>: the name people see on the site's Permission Levels page.
  • <description>: the text shown next to the name on that page.
  • <high> and <low>: the level's permissions, written as two numbers. The next section shows how to work them out.

Microsoft's Users, groups, and roles REST API reference gives this body under RoleDefinitionCollection, with an Order as well. I left Order out: SharePoint then gave the level the order 2147483647, the same order it gave a level created by hand on the Permission Levels page, and listed it last on that page.

How High and Low Work​

Every permission has a number in Microsoft's PermissionKind list: View Items is 1, Add Items is 2, Edit Items is 3, and so on up to 41, with two special ones above that. Microsoft's SPBasePermissions says the permissions are flags that allow a bitwise combination of its member values: each permission is one bit, and a level is all its bits added together.

The REST API sends those bits as two numbers. Microsoft's reference doesn't say how they're split, so I worked it out from the PermissionKind numbers and checked it against SharePoint's own levels:

  • Permissions 1 to 32 are in Low. Permission n adds 2 to the power of (n − 1).
  • Permissions 33 to 64 are in High. Permission n adds 2 to the power of (n − 33).

Decoding the numbers of Read, Contribute, Edit and Design this way gives exactly the permissions Microsoft lists for each of those levels in User permissions and permission levels.

You don't need to add up every bit by hand. Start from a built-in level that's close, read its two numbers in the browser (How to See a SharePoint Permission Level's Permissions in the Browser), and add or take away the permissions that differ. These are the list permissions, all in Low:

PermissionPermissionKindAdds to Low
View Items11
Add Items22
Edit Items34
Delete Items48
Approve Items516
Open Items632
View Versions764
Delete Versions8128
Manage Lists122048

For example, Read is High 176 and Low 138612833. Read plus Add Items is High 176 and Low 138612833 + 2 = 138612835.

The Example​

A level called Read and Add lets people see and add items, but not edit or delete them: Read plus Add Items. It's created on the root site contoso.sharepoint.com. The flow, Create a Permission Level, has four parts:

  1. Manually trigger a flow (How to Create an Instant Cloud Flow Inside a Solution in Power Automate).
  2. Find the permission level, the GET.
  3. If the permission level is missing, a condition.
  4. Create the permission level, the POST, in the condition's True branch.

Prerequisites​

  • Full Control of the site for the account the flow's SharePoint connection uses. Creating permission levels needs the Manage Permissions permission, which only Full Control includes by default.

Step 1: Look for the Level​

Add Send an HTTP request to SharePoint and rename it Find the permission level:

FieldValue
Site AddressYour site
MethodGET
Uri_api/web/roledefinitions?$filter=Name eq 'Read and Add'&$select=Id
HeadersAccept: application/json;odata=nometadata

The Find the permission level action with Site Address Communication site, Method GET, the Uri _api/web/roledefinitions?$filter=Name eq 'Read and Add'&$select=Id and the Accept header application/json;odata=nometadata

Step 2: Check the Answer​

Add a Condition called If the permission level is missing (How to Add a Condition in Power Automate). On the left, add this expression (How to Add an Expression in Power Automate); choose is equal to; on the right, add the expression true:

If the permission level is missing → left value
empty(body('Find_the_permission_level')?['value'])

body('Find_the_permission_level') is the answer of the GET, ?['value'] is its list of matching levels, and empty() is true when that list has nothing in it. In expressions, an action is named with underscores for its spaces.

Step 3: Create the Level​

In the True branch, add Create the permission level:

FieldValue
Site AddressYour site
MethodPOST
Uri_api/web/roledefinitions
HeadersAccept: application/json;odata=nometadata
Content-Type: application/json;odata=verbose
Create the permission level → Body
{
"__metadata": { "type": "SP.RoleDefinition" },
"Name": "Read and Add",
"Description": "Can view and add list items, but not edit or delete them.",
"BasePermissions": {
"__metadata": { "type": "SP.BasePermissions" },
"High": "176",
"Low": "138612835"
}
}

The Create the permission level action with Method POST, the Uri _api/web/roledefinitions, the Accept and Content-Type headers, and the Body with type SP.RoleDefinition, Name Read and Add, the description, and BasePermissions High 176 and Low 138612835

Step 4: Run the Flow​

Save the flow and test it manually (How to Test a Cloud Flow Manually in Power Automate). The level didn't exist yet, so the condition was true and Create the permission level ran:

The run of Create a Permission Level with green ticks on Manually trigger a flow, Find the permission level, If the permission level is missing and, in its True branch, Create the permission level; the False branch has no actions

When the level already exists, Find the permission level returns its ID, the condition is false, and nothing is created.

The Result​

Site settings > Site permissions > Permission Levels lists Read and Add with its description:

The Permission Levels page listing Full Control, Design, Edit, Contribute, Read and, boxed in red, Read and Add with the description Can view and add list items, but not edit or delete them.

Selecting it shows its permissions. In List Permissions, Add Items is ticked along with Read's View Items, Open Items, View Versions, Create Alerts and View Application Pages, while Edit Items and Delete Items are not:

The List Permissions section of Read and Add, with Add Items, View Items, Open Items, View Versions, Create Alerts and View Application Pages ticked, and Manage Lists, Override List Behaviors, Edit Items, Delete Items, Approve Items and Delete Versions not ticked

I left that page with the browser's Back button, without saving anything.

Common Mistakes​

MistakeWhat happensDo this instead
Creating without looking firstEvery run tries to create the level againLook for the level and create it only when it's missing
Working out Low from scratchOne wrong bit gives the level a permission you didn't meanStart from a built-in level's numbers and add or take away
Leaving out the __metadata linesSharePoint can't tell what the body describesKeep both type lines
Running the flow with an account that isn't a site ownerSharePoint refuses the POST, because creating levels needs Manage PermissionsUse an account with Full Control of the site

Troubleshooting​

SymptomLikely causeFix
Create the permission level fails with Invalid JSONThe body isn't valid JSONCheck the quotes and commas, as in Fixed: "Invalid JSON. A Token Was Not Recognized in the JSON Content"
An access-denied errorThe connection's account can't manage permissionsUse an account with Full Control
The level is created again on every runThe name in $filter doesn't match the name in the bodyUse exactly the same name in both
The level has the wrong permissionsHigh or Low is offCompare its permissions page with what you meant, and recalculate

FAQ​

Can I change a level's permissions later?​

Yes, on its page under Permission Levels, as in How to Create a Custom Permission Level in SharePoint. The flow doesn't change a level that already exists, because it only creates one when the name is missing.

Why are the numbers strings in the body?​

Microsoft's reference writes them as strings, 'High': '176', and SharePoint accepted them that way, so the example does the same.

How do I make a level without delete?​

Take Delete Items (8) and Delete Versions (128) away from Contribute: Low 1011028719 − 136 = 1011028583, with High 432. That's the Contribute Without Delete level the Overtime Timesheet setup flow creates.

Does this need a premium licence?​

No. Send an HTTP request to SharePoint is part of the standard SharePoint connector.

Conclusion​

Look for the level with _api/web/roledefinitions?$filter=Name eq '<level name>', and when the value array is empty, POST an SP.RoleDefinition to _api/web/roledefinitions with its name, description and BasePermissions. Start from a built-in level's High and Low and add each permission's value, such as 2 for Add Items.

Additional Resources​