In Microsoft flow there is no built in action to add a user to a SharePoint group. One way to achieve this is to use the “Send HTTP request to SharePoint”
in this action you need to
- Set the URL of the Site
- Set method to “POST”
- URI set to “_api/web/sitegroups({GROUPID})/users”, example: _api/web/sitegroups(10)/users
- Add header with key=”accept” and value = “application/json;odata.metadata=none”
- Add header with key =”content-type” and value = “application/json”
- Set the Body to be {‘LoginName’:’i:0#.f|membership|[EMAIL ADDRESS]’}, example: {‘LoginName’:’i:0#.f|membership|john.doe@domain.onmicrosoft.com’}
It would look like this
This is tested with a SharePoint online connection but assume might work with on premise SharePoint as well.
Just a note here, because your blog doesn’t use unicode, people cannot cut and paste the “Body” above into Flow. The apostrophes are not actual apostrophes. You’ll need to change them to ” ‘ ” to get this to work.
Can i add wildcards to this? I want to add any user that has 123.com at the end of their username to a specific group
How HTTP request can be modified in order to _remove_ users from group instead of adding?
In addition to EricOnline’s comment. This is the correct body you can use:
{‘LoginName’:’i:0#.f|membership|john.doe@test.onmicrosoft.com’}
I tried using {‘LoginName’:’i:0#.f|membership|john.doe@test.onmicrosoft.com’} but no luck it gives nvalid JSON. The property name ” is not valid. The name of a property cannot be empty, when I replace quotes with ” quotes the I get Access denied message, I do have access to SP Group, is there anything I’m missing here, Thanks for the help .
I tried this and got an error:
-2147024809, System.ArgumentExceptionValue does not fall within the expected range.
Any idea? Thank you!