cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
golfnutt82
Helper IV
Helper IV

Transfer a User from One SP User Group to Another using REST API

Hello,
Is it possilble to move a person from one SP user group to another user group.
Lets say a user is in a "Read" only group but the manger wants to put them in a "Contributor" group?
This would need to be automated using REST. 
A manager would input the instruction on a SP list form triggering the workflow to do the heavy lifting.

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Power Participant
Power Participant

Hi, @golfnutt82 , I appreciate that you may have legacy SP groups and users, and there's definitely ways there too ... but have you looked at the Office 365 Groups actions?

 

If the users are all 365 groups members (which all modern SP / Teams groups are) then you can accomplish what you want using the "Remove member from group" and "Add member to group" actions therein.

 

I appreciate that you mentioned that you would like this to react to changes made by a manager on a SharePoint list's form input (that's just going to be a new/amended SP list trigger if that's it) but then you also said that you wanted this to be REST, too.

 

So if you *also* want to make this REST compatible, after testing it using a flow button or reacting to test entries on the list in question, you can change the trigger to an HTTP Request. For which you'll need to feed it the right input. But once you have that it will mean that you can then have a separate flow that simply calls the HTTP Request.

 

Responses can also be added for even more full REST compatibility.

 

However, like I say, if you just want it to react to the input on a SharePoint list, then make the trigger one of either SharePoint triggers "When an item is created" or "When an item is created or modified" and it'll fire accordingly.

 

EDIT - The following questions are important to discern if you're doing this for the user groups defined in SP Sites:

  1. Do you already have access to the specific SP.Group user group Title and/or Id that you wish to remove from and add to?
    ie. have you already extracted / automated this information for the form that is affecting the changes?
  2. Do you already have access to the specific SP.User and their LoginName that you wish to remove from and add to?
  3. If either of those isn't quite set up, yet. Are you trying to basically build a user management app? 

If the answer to that third question is "yes" I'm sure someone around here might be kind enough to help do the whole thing for you. However, and I say this with kindness, you will almost definitely be more rewarded finding someone in your company that could build this for you. As there is almost definitely someone doing a low level job that could.

 

Still, if you just wish to add and remove users to and from a group with HTTP calls, use the setups below, where:

_GROUP_ID_ =The Id of the SP.Group user group
_USER_LOGINNAME_=The LoginName of the SP.User user
_USER_EMAILADDR_=The Email of the SP.User user

 

To add a user:

Method POST
URI /_api/web/sitegroups/GetById("_GROUP_ID_")/users
Headers
KeyValue
Acceptapplication/json;odata=verbose
Content-Typeapplication/json;odata=verbose
X-RequestDigest$("#__REQUESTDIGEST").val()
BODY

{

  "__metadata": {

    "type": "SP.User"

   },

 "LoginName": "_USER_LOGINNAME_"

}

 

To remove a user:

Method POST
URI /_api/web/sitegroups/GetById("_GROUP_ID_")/users/getbyemail('_USER_EMAILADDR_')
Headers
KeyValue
Acceptapplication/json;odata=verbose
Content-Typeapplication/json;odata=verbose
IF-MATCH*
X-HTTP-MethodDELETE
X-RequestDigest$("#__REQUESTDIGEST").val()
BODY 

 

If you want to do any more, I would suggest perhaps reading the SharePoint REST documentation online, there is quite a bit, there is also the Graph docs, too.


To be completely honest with you, that's how I have provided the above, along with some internet searching based on that.

 

View solution in original post

1 REPLY 1
eliotcole
Power Participant
Power Participant

Hi, @golfnutt82 , I appreciate that you may have legacy SP groups and users, and there's definitely ways there too ... but have you looked at the Office 365 Groups actions?

 

If the users are all 365 groups members (which all modern SP / Teams groups are) then you can accomplish what you want using the "Remove member from group" and "Add member to group" actions therein.

 

I appreciate that you mentioned that you would like this to react to changes made by a manager on a SharePoint list's form input (that's just going to be a new/amended SP list trigger if that's it) but then you also said that you wanted this to be REST, too.

 

So if you *also* want to make this REST compatible, after testing it using a flow button or reacting to test entries on the list in question, you can change the trigger to an HTTP Request. For which you'll need to feed it the right input. But once you have that it will mean that you can then have a separate flow that simply calls the HTTP Request.

 

Responses can also be added for even more full REST compatibility.

 

However, like I say, if you just want it to react to the input on a SharePoint list, then make the trigger one of either SharePoint triggers "When an item is created" or "When an item is created or modified" and it'll fire accordingly.

 

EDIT - The following questions are important to discern if you're doing this for the user groups defined in SP Sites:

  1. Do you already have access to the specific SP.Group user group Title and/or Id that you wish to remove from and add to?
    ie. have you already extracted / automated this information for the form that is affecting the changes?
  2. Do you already have access to the specific SP.User and their LoginName that you wish to remove from and add to?
  3. If either of those isn't quite set up, yet. Are you trying to basically build a user management app? 

If the answer to that third question is "yes" I'm sure someone around here might be kind enough to help do the whole thing for you. However, and I say this with kindness, you will almost definitely be more rewarded finding someone in your company that could build this for you. As there is almost definitely someone doing a low level job that could.

 

Still, if you just wish to add and remove users to and from a group with HTTP calls, use the setups below, where:

_GROUP_ID_ =The Id of the SP.Group user group
_USER_LOGINNAME_=The LoginName of the SP.User user
_USER_EMAILADDR_=The Email of the SP.User user

 

To add a user:

Method POST
URI /_api/web/sitegroups/GetById("_GROUP_ID_")/users
Headers
KeyValue
Acceptapplication/json;odata=verbose
Content-Typeapplication/json;odata=verbose
X-RequestDigest$("#__REQUESTDIGEST").val()
BODY

{

  "__metadata": {

    "type": "SP.User"

   },

 "LoginName": "_USER_LOGINNAME_"

}

 

To remove a user:

Method POST
URI /_api/web/sitegroups/GetById("_GROUP_ID_")/users/getbyemail('_USER_EMAILADDR_')
Headers
KeyValue
Acceptapplication/json;odata=verbose
Content-Typeapplication/json;odata=verbose
IF-MATCH*
X-HTTP-MethodDELETE
X-RequestDigest$("#__REQUESTDIGEST").val()
BODY 

 

If you want to do any more, I would suggest perhaps reading the SharePoint REST documentation online, there is quite a bit, there is also the Graph docs, too.


To be completely honest with you, that's how I have provided the above, along with some internet searching based on that.

 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (3,235)