SharePointCass

SharePointCass

SharePoint Online REST APIs (Part VI): Permissions

In the SharePoint Online REST APIs series, I’ll be sharing the most common APIs I use. I mainly use these APIs in Power Automate, so I’ll base the information in this series on the data you need for a Send an HTTP request to SharePoint action.

This article explores how to break and grant permissions to users and SharePoint Online groups. This is not a comprehensive list; rather a list of calls that I use when I can’t use predefined Power Automate actions. I have used the color red to identify interchangeable values.

Check if a subsite has unique permissions

_api/web?$select=HasUniqueRoleAssignments

This call checks to see if a site is inheriting from its parents, or has broken inheritance. This call can also work on lists, libraries, folders and items (see below).

Check if an item has unique permissions

_api/web/lists(guid' GUID ')/items( 40 )?$select=HasUniqueRoleAssignments

As mentioned above, this call checks to see if a specific item has unique permissions. In this example, I am looking at an item in a specific library that has an ID of 40 .

Break permission inheritance on an item

_api/web/lists/GetByTitle(' Site Pages ')/items( 5 )/BreakRoleInheritance(CopyRoleAssignments=true, ClearSubscopes=true)

This example breaks inheritance on a site page. However, you can also use this call to break permission inheritance on a site, list, library or item. BreakRoleInheritance essentially breaks the inheritance. The CopyRoleAssignments and ClearSubscopes are parameters which can be true or false. For more information on these parameters, read this article .

Get user principal ID

_api/web/SiteUsers/GetByEmail(' [email protected] ')/Id

After you’ve broken inheritance, you need to add users (or groups; which is explored next). Before you can add a user to an item/site/list etc., you’ll need to get their Id .

Get group principal ID

_api/web/SiteGroups/GetByName(' Site Name Owners ')?$select=Id

This is the same concept as above, however, it is getting the Id of a SharePoint group.

Give permissions to a user or group

_api/web/lists/GetByTitle(' Site Pages ')/items( 5 )/RoleAssignments/AddRoleAssignment(PrincipalId= 9 ,RoleDefId= 1073741827 )

Finally, we can grant permissions to a user or group. To do this, we need the principal Id (which we got in the above calls) and the value for RoleDefId . These values are not straight forward. I have included the main permissions in the table below, but Microsoft details some more on their site .

Permission LevelRoleDefId Value
1073741829
1073741827
1073741826

' src=

Published by SharePointCass

I've been in the Microsoft world for over 10 years. I started out as a SharePoint developer but have since found myself intrigued by other aspects of Microsoft 365 including the Power Platform, Stream and Teams. I like to consider myself a sucker for organizational collaboration business systems, and this blog explores how to achieve the best out of these applications. View all posts by SharePointCass

4 Replies to “SharePoint Online REST APIs (Part VI): Permissions”

  • Pingback: Resolved: how to manage people that can access to folders in SharePoint using API - Daily Developer Blog

Hi. Unfortunately, my groupID and userID are the same (yes, the same integer number). How can I grant permissions to a library item only with user email address?

Hi , I want create a sharing link of SharePoint documents for external users using REST API with PHP.Could me help me out how I can achieve this. waiting for your reply.

Hi, how do I create a new user group please? That part was missing in the article. Thanks much.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

Notify me of follow-up comments by email.

Notify me of new posts by email.

Working Man's SharePoint

Managing Role Assignments/Permissions with SharePoint REST Part2

In my last post I described many of the REST endpoints available in SharePoint to manage role assignments. In this post, I will provide a concrete example of using these endpoints in a provisioning-like scenario. I say provision-like because real provisioning scenarios tend to be very specific and one-offs (i.e. I need 7 sites, each with 5 lists and 3 groups, based on a naming convention by organization, and these permissions, and blah and blah and blah). Such specific requirements can’t be written into a one size fits all solution, so I’m just going to mimic them by creating a whole bunch of role assignments, and then deal with some of the issues of initiating a bunch of ajax calls in a short period of time.

What We’re Building

I want to build a page that demonstrates what a provisioning scenario might look like. Namely, this is a whole lot of individual REST service calls, which presents some unique challenges when implementing in JavaScript in the browser.

In the interface below, you can choose a SharePoint group, one or more SharePoint lists in the current site, and one or more role definitions, and with one click you can assign each of those role definitions to that SharePoint group for each of those SharePoint lists. As filled out below, there are 6 lists and 4 role definitions to be applied to the group “CSRDemos Members”.

So the first thing I need to do is check each list to see if role inheritance isn’t broken (that’s 6 lists, so 6 REST calls and 6 network connections). Then if role inheritance isn’t broken, I need to break it (6 more REST service calls), and if it is already broken I need to delete each list’s role assignments for the SharePoint group (also 6 REST service calls, so stage 2 is 6 calls either way). And finally, I need to make 4 role assignments for each of 6 lists (i.e. 4×6 = 24 more REST service calls). Hmmm…that seems like a lot:

(6 hasuniquepermissions) + (6 breakroleinheritance/roleassignments) + (6 lists * 4 role definitions) = 36 REST calls

Piece of cake…right?

Manage Role Assignments Interface

And while you’re waiting, I pop up this nifty CSS-only spinner! What more could you ask for? I’ve said in previous REST posts that I could probably use some sort of busy indicator here or there, but this time I really need it.

Waiting for 36 REST Calls

Actually, it’s just not as bad as you might imagine. Below I show the console output from a run with these inputs. I log a bunch of console messages with things like how many connections I currently have open, the results from each service call, and finally the elapsed time. In the screenshot below, the elapsed time is 5.6 seconds. 36 REST calls in 5.6 seconds, I can live with that. And in fact, it could be much faster. I implement some throttling in my code, which is fancy tech talk for I slow it down some. Without that throttling, it takes roughly .7 to 1.5 seconds.

Finished in 5.6 seconds

Don’t believe me? It’s pretty clearly shown in the screenshot below. This is IE’s network tab in developer tools. It is currently showing the output from one button click with the above parameters, in other words the 36 REST service calls I described above. Notice how the network connections are bunched together in groups of 5. And as time progresses, a gap is clearly noticeable between those bunches.

That’s because I only open 5 network connections at a time. When I need more, I pause in one-second intervals and wait for old connections to be released before initiating new requests. This actually slows down the client quite a bit, but also reduces the load on the server quite a bit. It’s a trade-off, and you need to be aware of it if you’re going to implement anything that does bulk operations with SharePoint (REST or not). You can’t always pound the server full-throttle without eventually getting nasty calls from your farm administrators (or if you are a farm admin, you’re customers).

Now one of the knocks on REST vs CSOM is that CSOM has support for batch operations. In truth, so does SharePoint REST, but it’s very cumbersome and not even available until 2016. And anyway, realize that batching is a trade-off too. By opening multiple connections you can perform many operations in parallel, but at a cost of more resources used on both the client and the server, and you can tweak that with throttling. By doing batch operations I use a lot fewer resources on both the client and the server, but quite possibly the result appears slower to the end user because now all operations are executed on the server in serial, and the only way to tweak that is with more and better hardware. Or at least changesets are executed in serial (see the second Andrew Connell post referenced below). Batch operations within a changeset may be serial or may be parallel, but either way it’s not up to you.

Network shows connections bunched once per second

Now let’s say I had a more realistic scenario like say I had the same 6 lists in 10 sub-sites, and I needed to add role assignments to 3 different groups. But as long as we’re shooting for realism, let’s say I only need one role definition for each group, because there is really no reason to ever need more than one. If I need the union of permissions of 2 permission levels I can create a custom level with those permissions. And most permission levels have a privilege/subordinate relationship anyway, meaning Designer is Contributor+. So there’s no reason to assign a group Contributor and Designer, just Designer will do. I just did it above to generate a lot of connections and see how it performed. So anyway, here’s what this scenario looks like:

10 sites * 6 lists * 2 service calls (hasuniquerollassignments and breakinheritance/removeperms) = 120 service calls

10 sites * 6 lists * 3 groups * 1 role assignment = 180 service calls

So if I can do 36 REST calls in 5.6 seconds with throttling, I can extrapolate that 300 similar REST calls would take approximately 46 seconds with the same throttling. And I can adjust the throttling to reduce the server load or increase the speed as needed (to a degree). 46 seconds might seems like a lot of time, but at least you get to look at my beautiful spinner while you’re waiting, and that would be roughly on the order of magnitude of 10 seconds without any throttling. And keep in mind that this is provisioning code. It probably only needs to be run once, or maybe once each time a new sub-site is added, can probably be run on off-peak hours, and therefore maybe neither performance nor server load is that much of a consideration. And if you want to do a lot of work, it’s going to take a bit of time. Even if you do it all manually, the server’s still going to end up doing the same work, albeit not all at once.

Either way, this is starting to look doable, even from JavaScript in the browser. There does come a point where it starts to look more like a job for PowerShell, but since many SCAs have neither the skills nor the option to run PowerShell against their site, anything in the range of 30-60 seconds is reasonably doable in the browser. Even longer really, but ideally you should provide a bit more than a pretty spinner to show that something is happening if it’s going to go much longer. Like maybe show the most recent console log message above the spinner. Some quick changing text like that can be very reassuring to the user that they’re not just locked up, even if it’s too fast to read.

Provisioning Role Assignments with Code

The sample code for this post is pretty big, so I’ll make no effort to show it all here. Much of it is just the same stuff I showed in my last post with the $.ajax calls converted to fetch. I’m just going to show some of the more interesting bits. Most of the code is encapsulated in an object literal called roleDefinitionManager (or rdm for short). The action starts with the rmd.init method:

: function() { rdm.initGroupSelect(); rdm.initListSelect(); rdm.initRoleDefinitionSelect(); var doIt = document.getElementById("doItNow"); doIt.addEventListener("click", function(e) { // construct an object that describes all the things we need to do rdm.todo = {}; rdm.todo.principalId = document.getElementById("siteGroup").value; rdm.todo.lists = rdm.getValues(document.getElementById("listsSelected"), true); rdm.todo.roleDefIds = rdm.getValues( document.getElementById("roleDefinitionsSelected"), false); console.log(JSON.stringify(rdm.todo, null, 4)); // validate required inputs var errors = rdm.validateRequired(rdm.todo.principalId.length < 1, "groupError"); errors += rdm.validateRequired(rdm.todo.lists.length < 1, "listsError"); errors += rdm.validateRequired(rdm.todo.roleDefIds.length < 1, "roleDefinitionsError"); // reset connection statistics rdm.connectionCount = 0; rdm.totalReleased = 0; rdm.totalExpected = rdm.todo.lists.length + (rdm.todo.lists.length * rdm.todo.roleDefIds.length); // if nothing failed validation if(errors === 0) { // start setting role assignments rdm.setRoleAssignments(); } }); ,

First it initializes the options for the 3 select elements for group, lists, and role definitions. Then it sets up a click handler for the terribly named “Do it now” button. When that button is clicked, it summarizes what is to be done in a member property called todo, and then calls setRoleAssignments shown below. It also initializes some member properties used for connection management, but that will be easier to explain in a later code block.

: function() { rdm.startTime = new Date(); try { for (var i = 0; i & lt; rdm.todo.lists.length; i++) { var list = rdm.todo.lists[i]; rdm.setRoleAssignmentsOnList(list); } } catch (e) { document.getElementById("spinnerOverlay").style.display = "none"; } , : function(list) { var doListInternal = function () { url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + list + "')/hasuniqueroleassignments"; fetch(url, { method: 'GET', credentials: 'include', headers: { 'accept': 'application/json;odata=nometadata' } }).then(function (response) { if (response.status !== 200) { throw new Error(response.status + " " + response.statusText); } return response.json(); }).then(function (json) { console.log("hasuniqueassignments(" + list + ")" + " returned " + JSON.stringify(json, null, 4)); if (json.value) { rdm.removeGroupPermissions(list); } else { rdm.breakRoleInheritance(list); } }).catch(function (error) { alert(JSON.stringify(error, null, 4)); }); }; // execute immediately if {connectionMax} is not exceeded, otherwise // try again every {interval} milliseconds until {connectionMax} is // not exceeded, and then execute rdm.executeOrDelayUntilConnectionAvailable( doListInternal, rdm.interval); ,

setRoleAssignments just loops through the lists and calls setRollAssignmentsOnList. It just mostly does a call to the REST endpoint hasuniquerollassignments on the list. It does this to see if it should then break role inheritance, or just delete any role assignments from the list for the principal id. The code for these methods is omitted as uninteresting, but either of them ultimately calls a method that creates the new role assignments on the list. The more interesting thing in the above code is that the web service call is encapsulated in the nested method doListInternal, and the setRollAssignmentsOnList method ends with a call to executeOrDelayUntilConnectionAvailable.

If you’ve been doing any SharePoint JavaScript code, you must have heard about ExecuteOrDelayUntilScriptLoaded. executeOrDelayUntilConnectionAvailable (shown below) does basically the same thing but with different criteria for delaying. reserveConnection just increments a counter of connections and returns the current counter if a connection is available (i.e. max connections would not be exceeded). If no connection is available, it returns 0. releaseConnection just decrements that counter. So executeOrDelayUntilConnectionAvailable tries to reserve a connection and call the callback. If it cannot, it calls setInterval with the interval passed in and upon waking up tries again, over and over every interval until it successfully reserves a connection and calls the callback. Obviously, this is where the throttling can be tweaked, mostly by adjusting the maximum connections and/or the interval.

Note that each browser has a maximum number of concurrent connections and a lower maximum number of concurrent connections per host. When I started this, a fundamental misunderstanding led me to believe I had to do something like this reserve connection scheme because of these limits. But if you ask for more connections than the browser allows it doesn’t fail (at least not until a very high number in modern browsers). The browser just queues up your request and makes the connection when one is available much as I am doing. Still, doing it myself does allow me to throttle my requests which is quite useful. So if I set the maximum to 100, I’ll always reserve a connection as soon as I ask so I’ll plow ahead as soon as the browser will let me. If you look at the network tab of the developer tools, you’ll see that it still doesn’t open up 36 connections at once, there are just no appreciable gaps between close and open. I wouldn’t be surprised if there is still some high limit beyond which the browser will barf, but I haven’t hit it, and it’s probably browser specific.

: 0, : 0, : 0, : null, : null, : 5, : 1000, : function(callback, interval) { if(rdm.reserveConnection()) { callback(); } else { // check every 250ms if there is a connection available to us var i = setInterval(function() { console.log("checking for connection again"); // returns false if we have too many connections if(rdm.reserveConnection()) { console.log("got connection after waiting"); // not too many connections, do our work callback(); // release the timer clearInterval(i); } // otherwise, try again in 250ms }, interval); } , : function() { console.log("reserving connection, count = " + rdm.connectionCount); rdm.connectionCount++; if(rdm.connectionCount > rdm.connectionMax) { console.log("waiting for connection, count = " + rdm.connectionCount); rdm.connectionCount--; return 0; } document.getElementById("spinnerOverlay").style.display = "block"; return rdm.connectionCount; , : function() { console.log("releasing connection, count = " + rdm.connectionCount); rdm.connectionCount--; rdm.totalReleased++; if(rdm.totalReleased === rdm.totalExpected) { rdm.endTime = new Date(); var elapsed = Math.round((rdm.endTime - rdm.startTime) / 100); console.log("elapsed time: " + elapsed/10); document.getElementById("spinnerOverlay").style.display = "none"; } return rdm.connectionCount; ,

And that’s really all the code I’m going to dump on you here. The rest of it is more of the same, I described the more interesting REST-related bits in my last post, and as usually I’ll include a download to a complete working page at the end of the post.

Sum Up Role Assignments Sample

The code for this sample was really quite the PITA, which is why I split this post into two parts. At some point it would be interesting to redo this using batch operations à la the Andrew Connell articles referenced below. But I wouldn’t do that without writing some kind of wrapper around the painfully tedious multi-part mime parsing described in those articles, and I’ll make no promises about when I might get around to that.

ManageRoleAssignments.aspx

  • Browserscope – information about connection limits in many modern browsers
  • Part 1 – SharePoint REST API Batching – Understanding Batching Requests – Andrew Connell
  • Part 2 – SharePoint REST API Batching – Exploring Batch Requests, Responses and Changesets – Andrew Connell

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Pocket (Opens in new window)

Leave a Comment Cancel reply

You must be logged in to post a comment.

Logo

Access SharePoint API with application account – my ultimate guide

Table of contents:

I have been struggling with this topic for some time. Almost every time, when I was supposed to work with SharePoint API in Power Apps or Logic Apps, I was googling and going through the same partial solutions.

Just to find out in the end, that it is missing some crucial pieces or that despite all, it doesn’t work. This is why I decided to write this post to help myself in the future and maybe you as well! Let’s get started. For the solution I am going to use Azure Key Vault to store important secrets.

Step 1 – generate new self-signed certificate in Azure Key Vault

When in Azure Key Vault, navigate to Certificates and click “Generate/Import” button:

add role assignment sharepoint rest api

Next, give it a name you will remember, and under subject type: CN=sharepoint.com. You can set additional options per your needs:

add role assignment sharepoint rest api

Once a certificate is “Completed”, click on its name:

add role assignment sharepoint rest api

Then on the latest, aka current version:

add role assignment sharepoint rest api

And from there click on “Download in CER format”. Save it somewhere, and we will get back to it 😉

add role assignment sharepoint rest api

Next navigate to “Access configuration” of the Key Vault, and switch the permission model to use Azire role-based access control (RBAC) – it will be important later:

add role assignment sharepoint rest api

Step 2 – register application in Azure Entra ID

Now, navigate to Entra ID and register new application :

add role assignment sharepoint rest api

Give it a name and select the “Accounts in this organizational directory only” option. Then hit register. Once the app is registered, navigate to “Certificate & secrets” page:

add role assignment sharepoint rest api

Switch to “Certificates” area and click “Upload certificate”:

add role assignment sharepoint rest api

Select the *.cer file you have downloaded in the last action from step no. 1. Give it a description. Click “Add”:

add role assignment sharepoint rest api

Step 3 – grant api permissions

Now you need to define what permissions the app is going to have. Navigate to API permissions and click “+ Add permission”:

add role assignment sharepoint rest api

As this post is about SharePoint access, I will focus on granting the app application permissions to access SharePoint. So from APIs, select SharePoint:

add role assignment sharepoint rest api

Next “Application permissions”, and then depending on what your app will need to do. If just read – grant it Sites.Read.All, if more – up to. I grant my app Sites.FullControll.All:

add role assignment sharepoint rest api

Once you have granted these permissions, you will need to grant admin consent on behalf of the whole organisation. If you have sufficient permissions – good for you. If not, you need to find the right admin to grant that:

add role assignment sharepoint rest api

After the consent is granted:

add role assignment sharepoint rest api

Step 4 – create logic app

Now create a new Logic App. Select whichever hosting option suits your needs the best. Then grant its name and select region. Remember, that the region is THE SAME AS THE AZURE KEY VAULT . Once a new Logic App is created, go to the resource. Expand “Settings” and navigate to “Identity”. Switch the status to “On” (and Save):

add role assignment sharepoint rest api

Wait a while, then click “Azure role assignments” button:

add role assignment sharepoint rest api

Next click the “Add role assignment” button, next set the below values:

  • Scope – Key Vault
  • Subscription – the one under which you have created the key vault from step no. 1
  • Resource – Azure Key Vault you created.
  • Role – Key Vault Certificate User

And click Save.

add role assignment sharepoint rest api

Navigate back to the logic app details. And switch to the Designer! Let’s build the process! 🙂

add role assignment sharepoint rest api

Step 5 – build the process

After placing a trigger action, add the “Get secret” action from Azure Key Vault set of actions. Then, configure the connection. Under “Authentication Type” select “Managed identity”:

add role assignment sharepoint rest api

And then name the connection, and type in the name of the Key Vault from Step no. 1 😉 Next, select the certificate you created in Step no. 1:

add role assignment sharepoint rest api

Now, add the “HTTP” action, and configure it as below:

  • URI – this is the site URL and the SharePoint API endpoint + any odata parameters.
  • Method – depending on the method
  • Headers – again, depending on the method. For GET, you need just Accept header. For POST, as well the Content-Type and so on…
  • Body – sometimes when doing POST requests, this is where you put request body.
  • Advanced parameters – select Authentication.

add role assignment sharepoint rest api

  • Authentication – select Active Directory OAuth.
  • Tenant – GUID representing Tenant ID. You can get it from the “Overview” page in Azure Entra ID:

add role assignment sharepoint rest api

  • Audience – your SharePoint URL, e.g., https://poszytek.sharepoint.com.
  • Client ID – ID of the app registered in Step no. 2. You can get the value from “Overview” page of the registered app:

add role assignment sharepoint rest api

  • Credential Type – switch to Certificate
  • Pfx – Value from the “Get secret” action

add role assignment sharepoint rest api

Step 6 – tests!

Having these all steps completed, it is now time to save your Logic App and test it. Click “Save”, then refresh the designer, and click “Run”! And voilà! Congratulations! You made it work! 🙂

add role assignment sharepoint rest api

Related Posts

Photo by Hendrik Morkel on Unsplash

Access Graph API with application account – my ultimate guide

add role assignment sharepoint rest api

PVA series – authentication in Power Virtual Agent

Microsoft Flow

Add Office 365 group members using Microsoft Flow

add role assignment sharepoint rest api

Tomasz Poszytek

Hi, I am Tomasz. I am expert in the field of process automation and business solutions' building using Power Platform. I am Microsoft MVP and Nintex vTE.

No Comments

Post a comment cancel reply.

Save my name, email, and website in this browser for the next time I comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed .

Book consultancy services with me! Fill in the form below and let’s setup a call.

Name and lastname (required)

E-mail address (required)

Your message (required)

Bits & Pieces – A blog by Kannan Balasubramanian

Item level permission in SharePoint using REST and Power Automate

March 9, 2021 / Kannan / 0 Comments

Sometimes when an item is created we might need to set item level permission for those items. Fortunately, SharePoint’s REST API can help with this and Power Automate / Flow supports SharePoint HTTP calls.

For this to work, make sure the Power Automate is created with an account having site collection administrator access.

First the basics of how this works

Step 1 is to identify to whom the permissions should be granted to. It can be either a person or a group.

Step 2 is to identify what kind of permission i.e. role should be granted.

Step 3 is breaking the inheritance.

Step 4 is assigning the permission.

Second is knowing the supporting APIs to gather the information

Step 1: to whom the permission should be granted, individual user.

To identify the individual user the following API can be used. Commonly everyone relies on e-mail ID so lets take that as an example

When you use Power Automate, make sure to extract the ID and place it in a variable.

To identify the site group the following API can be used.

Step 2: What kind of permission?

This is defined by the role definitions available in the site. The following API will help in identifying the role definitions and their ID.

Step 3: Breaking the inheritance

For this first thing is we need to identify the target for which the inheritance should be broken. In the following example it’s a list item.

Step 4: Assigning permission

As said before permission can be assigned to an individual or a group. The following API will help with that

Following is the list of out of the box role definitions which I came across in the internet

Full Control1073741829
Design1073741828
Edit1073741830
Contribute1073741827
Read1073741826
View Only1073741924
Limited Access1073741825

You can refer the following URL which has code example to use REST api.

Set custom permissions on a list by using the REST interface

# Power Automate # SharePoint Online

Leave a Reply Cancel reply

Your email address will not be published / Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed .

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Role Assignments - Get

Get a role assignment by scope and name.

URI Parameters

Name In Required Type Description
path True

string

The name of the role assignment. It can be any valid GUID.

path True

string

The scope of the operation or resource. Valid scopes are: subscription (format: '/subscriptions/{subscriptionId}'), resource group (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or resource (format: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'

query True

string

The API version to use for this operation.

query

string

Tenant ID for cross-tenant request

Name Type Description
200 OK

Returns the role assignment.

Other Status Codes

Error response describing why the operation failed.

Permissions

To call this API, you must be assigned a role that has the following permissions. For more information, see Azure built-in roles .

Microsoft.Authorization/roleAssignments/read

Azure Active Directory OAuth2 Flow

Type: oauth2 Flow: implicit Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Name Description
user_impersonation impersonate your user account

Get role assignment by scope and name

Sample request.

To use the Azure SDK library in your project, see this documentation . To provide feedback on this code sample, open a GitHub issue

Sample response

Definitions.

Name Description

The resource management error additional info.

The error detail.

Error response

The principal type of the assigned principal ID.

Role Assignments

Error Additional Info

The resource management error additional info.

Name Type Description
info

object

The additional info.

type

string

The additional info type.

Error Detail

The error detail.

Name Type Description
additionalInfo

[]

The error additional info.

code

string

The error code.

details

[]

The error details.

message

string

The error message.

target

string

The error target.

Error Response

Error response

Name Type Description
error

The error object.

Principal Type

The principal type of the assigned principal ID.

Name Type Description
Device

string

ForeignGroup

string

Group

string

ServicePrincipal

string

User

string

Role Assignment

Role Assignments

Name Type Default value Description
id

string

The role assignment ID.

name

string

The role assignment name.

properties.condition

string

The conditions on the role assignment. This limits the resources it can be assigned to. e.g.: @Resource[Microsoft.Storage/storageAccounts/blobServices/containers:ContainerName] StringEqualsIgnoreCase 'foo_storage_container'

properties.conditionVersion

string

Version of the condition. Currently the only accepted value is '2.0'

properties.createdBy

string

Id of the user who created the assignment

properties.createdOn

string

Time it was created

properties.delegatedManagedIdentityResourceId

string

Id of the delegated managed identity resource

properties.description

string

Description of role assignment

properties.principalId

string

The principal ID.

properties.principalType

User

The principal type of the assigned principal ID.

properties.roleDefinitionId

string

The role definition ID.

properties.scope

string

The role assignment scope.

properties.updatedBy

string

Id of the user who updated the assignment

properties.updatedOn

string

Time it was updated

type

string

The role assignment type.

Additional resources

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Not able to fetch role assignments of an item in a list via SharePoint rest APIs

I am using azure AD credentials(username, password, client id and client secret) to create access token. I am able to fetch all the data from SharePoint except ACLs/ Role Assignments using SharePoint rest APIs. Need to know what permission is required in Azure to fetch ACL data from SharePoint?

  • azure-active-directory

Ritika Raina's user avatar

The issue was with permission. With AllSites.FullControl permission, I was able to retrieve data.

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged sharepoint azure-active-directory or ask your own question .

  • The Overflow Blog
  • Where developers feel AI coding tools are working—and where they’re missing...
  • He sold his first company for billions. Now he’s building a better developer...
  • Featured on Meta
  • User activation: Learnings and opportunities
  • Preventing unauthorized automated access to the network
  • Should low-scoring meta questions no longer be hidden on the Meta.SO home...
  • Announcing the new Staging Ground Reviewer Stats Widget

Hot Network Questions

  • If I was ever deported, would it only be to my country of citizenship? Or can I arrange something else?
  • FIFO capture using cat not working as intended?
  • How can I grep to include the surrounding lines?
  • Image localisation and georeference
  • Pulling myself up with a pulley attached to myself
  • What is the simplest formula for calculating the circumference of a circle?
  • Could you compress chocolate such that it has the same density and shape as a real copper coin?
  • Could you suffocate someone to death with a big enough standing wave?
  • Are there individual protons and neutrons in a nucleus?
  • How was the year spoken in late 1800s England?
  • is it okay to mock a database when writing unit test?
  • Player sprite becomes smaller during attack animation (Java)
  • An everyday expression for "to dilute something with two/three/four/etc. times its volume of water"
  • What exactly is a scratch file (starting with #)? Does it still work today?
  • How do I link a heading containing spaces in Markdown?
  • Does legislation on transgender healthcare affect medical researchers?
  • God and Law of Identity Paradox
  • Complexity of computing minimum unsatisfiable core
  • A sweet Nonodoku - Nonodoku
  • Is BitLocker susceptible to any known attacks other than bruteforcing when used with a very strong passphrase and no TPM?
  • Could a Project like Orion be built today with non nuclear weapons?
  • Lovecraftian (but not written by Lovecraft himself) horror story featuring a body of water that glowed blue at night due to the creatures in it
  • What causes, and how to avoid, finger numbness?
  • Using car seat in a plane

add role assignment sharepoint rest api

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

sharepoint workflow rest api add role assignment exception

I develop a workflow and i want to grant unique permission on item in list using sharepoint rest api

the rest service return exception

Value does not fall within the expected range

please advice

  • sharepoint-designer
  • sharepoint-server

wjervis's user avatar

  • i see their is no single quotes in the Items(1)...could you please put that and try again –  Waqas Sarwar MVP ♦ Commented Mar 2, 2015 at 18:31
  • Guess you would get another exception, but did you use POST verb? –  eirikb Commented Mar 2, 2015 at 20:54

Know someone who can answer? Share a link to this question via email , Twitter , or Facebook .

Your answer, sign up or log in, post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Browse other questions tagged sharepoint-designer workflow sharepoint-server rest roles or ask your own question .

  • The Overflow Blog
  • Where developers feel AI coding tools are working—and where they’re missing...
  • He sold his first company for billions. Now he’s building a better developer...
  • Featured on Meta
  • User activation: Learnings and opportunities
  • Preventing unauthorized automated access to the network

Hot Network Questions

  • Sticky goo making it hard to open and close the main 200amp breaker
  • Why would an escrow/title company not accept ACH payments?
  • Is BitLocker susceptible to any known attacks other than bruteforcing when used with a very strong passphrase and no TPM?
  • What should you list as location in job application?
  • How was the year spoken in late 1800s England?
  • What is the flaw in Cooper's argument?
  • Thunderbird will not create profile in chosen folder on a different partition
  • Lovecraftian (but not written by Lovecraft himself) horror story featuring a body of water that glowed blue at night due to the creatures in it
  • Is it common in modern classical music for timpani to play chromatic passages?
  • Purpose of sleeve on sledge hammer handle
  • How long have people been predicting the collapse of the family?
  • Musicians wearing Headphones
  • Can I breed fish in Minecraft?
  • Why do (some) LaTeX fonts have separate 8pt and 10pt font files?
  • Solving a "One Away.." connections group with nine guesses
  • CH in non-set theoretic foundations
  • What does mean by "offer accepted" in Mathjobs portal?
  • Player sprite becomes smaller during attack animation (Java)
  • A sweet Nonodoku - Nonodoku
  • A time-travel short story where the using a time-travel device, its inventor provided an alibi for his future murderer (his wife)
  • How important exactly is the Base Attack Bonus?
  • Could you suffocate someone to death with a big enough standing wave?
  • FIFO capture using cat not working as intended?
  • "Chrisma" and "Him"

add role assignment sharepoint rest api

C# Corner

  • TECHNOLOGIES
  • An Interview Question

SharePoint

Deleting Current Role Definition to the Group in SharePoint Using REST

add role assignment sharepoint rest api

  • Gowtham Rajamanickam
  • Apr 06, 2015
  • Other Artcile

In this example you will see how to delete the current role definition of the group in SharePoint using the REST.

  • Publish Your App

add role assignment sharepoint rest api

  • Close the Properties window.

add role assignment sharepoint rest api

  • Add a role assignment for the group to the list using the AddRoleAssignment method that binds the group to the role definition and adds the role to the list.

add role assignment sharepoint rest api

  • Office 365 Development Tools

C# Corner Ebook

SharePoint Framework (SPFx) A Developers Guide

IMAGES

  1. Managing Role Assignments/Permissions with SharePoint REST • Working

    add role assignment sharepoint rest api

  2. sharepoint online

    add role assignment sharepoint rest api

  3. Break Inheritance And Add Role Permissions Using REST API In SharePoint

    add role assignment sharepoint rest api

  4. Add List Item In Sharepoint Using Rest Api at Vincent Bradley blog

    add role assignment sharepoint rest api

  5. SharePoint Rest API

    add role assignment sharepoint rest api

  6. Sharepoint: Add AD group to SharePoint Online using REST API (2 Solutions!!)

    add role assignment sharepoint rest api

VIDEO

  1. Demo SharePoint REST API and Power Platform

  2. Azure CLI

  3. Learning Assignment 3 : Read List Item With SharePoint REST API Using Postman Tool

  4. PnP Webcast

  5. PowerApps

  6. Lesson127

COMMENTS

  1. Set custom permissions on a list by using the REST interface

    The code example in this article sets custom permissions on a list, and then changes a group's permissions to it. The example uses the REST interface to: Get the ID of the target group. The example uses the group ID to get the current role bindings for the group on the list and to add the new role to the list.

  2. Break Inheritance And Add Role Permissions Using REST API In SharePoint

    In order to do that we can navigate to the permissions management section of the Library/List Library. Settings -> Permissions for this Document Library. Clicking on Stop Inheriting Permissions will grant unique permissions to the document library. In one of my project engagements, I however had to implement this using REST API and add Role ...

  3. Managing Role Assignments/Permissions with SharePoint REST

    To assign permissions in SharePoint, you make one or more role assignments, which requires three things: Some kind of handle for a securable object. That's basically a site, list, library, folder, document, or item. The principal id for something to which roles can be assigned. That's either an Active Directory user or security group, or a ...

  4. SharePoint Online REST APIs (Part VI): Permissions

    In the SharePoint Online REST APIs series, I'll be sharing the most common APIs I use. I mainly use these APIs in Power Automate, so I'll base the information in this series on the data you need for a Send an HTTP request to SharePoint action. This article explores how to break and grant permissions to users and SharePoint Online groups.

  5. Add Role Assignment using Office 365 group

    SharePoint rest API (add role assignment function) is scoped in SharePoint service, while Office 365 group is for the tenant and it's stored as directory object in Azure AD. They're 2 different concepts.

  6. Managing Role Assignments/Permissions with SharePoint REST Part2

    So the first thing I need to do is check each list to see if role inheritance isn't broken (that's 6 lists, so 6 REST calls and 6 network connections). Then if role inheritance isn't broken, I need to break it (6 more REST service calls), and if it is already broken I need to delete each list's role assignments for the SharePoint group ...

  7. Manage File permissions using REST API

    In that case the collection of role assignments must contain only 1 role assignment containing the current user after the operation. Step 2 (optional) Add/remove the role assignment on the List Item. Remove the current role assignment for the group on the File: Authorization: "Bearer " + accessToken.

  8. permissions

    You could use the following powershell script to add your account to the site collection before hand, you could also provision the onedrive sites. I'm working on a similar project myself. Onedrive for Business - Assign a user as a site collection administrator to OneDrive for Business sites

  9. Role Assignments

    Create or update a role assignment by scope and name. Create or update a role assignment by ID. Delete a role assignment by scope and name. Delete a role assignment by ID. Get a role assignment by scope and name. Get a role assignment by ID. List all role assignments that apply to a resource. List all role assignments that apply to a resource ...

  10. rest

    1. You could use the Rest API in order to break inheritance/delete unique assignments, add permissions to unique users or groups. You can check out some examples on this link. You can also use Power Automate SharePoint Connector Actions in order to achieve the same result. Here are some of the actions you can take: I hope these were some of the ...

  11. Access SharePoint API with application account

    Next click the "Add role assignment" button, next set the below values: Scope - Key Vault; Subscription - the one under which you have created the key vault from step no. 1; Resource - Azure Key Vault you created. Role - Key Vault Certificate User; And click Save.

  12. Role Assignments

    Name Required Type Description; properties.principalId True string The principal ID. properties.roleDefinitionId True string The role definition ID.

  13. Item level permission in SharePoint using REST and Power Automate

    Step 1 is to identify to whom the permissions should be granted to. It can be either a person or a group. Step 2 is to identify what kind of permission i.e. role should be granted. Step 3 is breaking the inheritance. Step 4 is assigning the permission.

  14. What permissions do I need to get RoleAssignments via the rest api?

    I am trying to get the ACL on a file via the rest api. I can get the contents of a file and make other rest calls but when I call: ... Does your user have permissions to modify role assignments? - Sergei Sergeev. Commented Nov 11, 2016 at 13:40 ... Sharepoint 2013 REST API - Shared Documents / Author Info In one Call? 4.

  15. Assigning New Role Definition to the Group in SharePoint Using REST

    In this example you will see how to assign a new role definition to the group in SharePoint using the REST. Develop the project using the following method in the NAPA Tool. On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project. Choose the App for SharePoint template, name the project Create Site ...

  16. Role Assignments

    Description of role assignment. properties.principalId string The principal ID. properties.principalType Principal Type. User The principal type of the assigned principal ID. properties.roleDefinitionId string The role definition ID. properties.scope string The role assignment scope. properties.updatedBy string

  17. SP REST

    You can assign permissions to SharePoint group using SharePoint REST API like: ... The group does not exist on the site I would like to add it, too. In order to do role assignment, the group needs to already exist on the site. I am taking a group from a parent site, and I'd like to add it to a child site. - user2004758.

  18. breakRoleInheritance and addRoleAssignment not working using rest api query

    Once user creates the folder, what i am trying to do is breakRoleInheritance on this folder and assign role only for creator of this folder and another two users.

  19. Not able to fetch role assignments of an item in a list via SharePoint

    Azure AD Custom Role - Permissions - Data Actions not returned in REST API - Role Definitions - Get 0 get appRoleAssignment permission description from REST API

  20. sharepoint workflow rest api add role assignment exception

    Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site

  21. Deleting Current Role Definition to the Group in SharePoint Using REST

    In this example you will see how to delete the current role definition of the group in SharePoint using the REST. Develop the project using the following method in the NAPA Tool. On your Developer Site, open the "Napa" Office 365 Development Tools and then choose Add New Project. Choose the App for SharePoint template, name the project Create ...