cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
smorley
Post Patron
Post Patron

Using Power Automate to remove user from a SharePoint group

Hi all,

I've successfully set up my flow to add users to a SharePoint group using the instructions from this post:

https://powerusers.microsoft.com/t5/Building-Flows/Adding-users-to-a-SharePoint-Group/td-p/309811

 

To remove a user from a group, I'm not quite following this solution:

https://powerusers.microsoft.com/t5/Connecting-To-Data/Use-Flow-to-Remove-User-from-Permissions-Grou...

 

I'm looking at Microsoft's documentation:

https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/dn5314...

 

Here's a screenshot of my flow.  It's grabbing the user information in the previous step of Get User Profile, but it's falling down on the URI and body steps.  Help would be appreciated.  (I hate syntax.)

 

removeuserfromSPgroup.jpg

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @smorley,


I see in the screenshot you are using a principalname value. Like mentioned in my previous reply, the loginname value will be slightly different. That is why it can't find your user.

 

A quick fix could be to concatenate the userPrincipal name with 'i:0#.f|membership|':

This example assumes your action before it is a Get User Profile (V2) (which you haven't renamed 😁) and that the user you are using in this test is an internal user and not a guest user (part of the tenant).

 

concat('i:0#.f|membership|',outputs('Get_user_profile_(V2)')?['body/userPrincipalName'])

 

concat_upn_withclaim.png

 

View solution in original post

4 REPLIES 4
Expiscornovus
Super User
Super User

Hi @smorley,

 

This method expects the loginName. A loginName field in SharePoint Online typically has something like: i:0#.f|membership|janedoe@contoso.onmicrosoft.com which is not the UPN. You probably need to change that in your string variable.

 

The Send an HTTP request to SharePoint action also needs some changes. First of all you want to use a POST method. I would also change the Accept header value. In the body I would also use the loginName property.

 

Below is an example of that approach:

 

removebyloginname_restapi.png

smorley
Post Patron
Post Patron

@Expiscornovus Definitely making some headway.

 

I've updated the action to reflect the changes you suggested.

smorley_0-1646152296847.png

The error message I get is: 

{"odata.error":{"code":"-2130575276, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The user does not exist or is not unique."}}}
clientRequestId: 6ae24fea-75c3-4c7a-b7fd-d1478b8f2184
serviceRequestId: fa8725a0-5061-1000-61dd-bbc02083e781

The error is referring to the body statement:

smorley_1-1646152375113.png

 

 

Expiscornovus
Super User
Super User

Hi @smorley,


I see in the screenshot you are using a principalname value. Like mentioned in my previous reply, the loginname value will be slightly different. That is why it can't find your user.

 

A quick fix could be to concatenate the userPrincipal name with 'i:0#.f|membership|':

This example assumes your action before it is a Get User Profile (V2) (which you haven't renamed 😁) and that the user you are using in this test is an internal user and not a guest user (part of the tenant).

 

concat('i:0#.f|membership|',outputs('Get_user_profile_(V2)')?['body/userPrincipalName'])

 

concat_upn_withclaim.png

 

smorley
Post Patron
Post Patron

@Expiscornovus FANTASTIC!!!!!!!!!!  THANK YOU SO MUCH!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (1,584)