cancel
Showing results for 
Search instead for 
Did you mean: 
siddharth_v

SharePoint Group Operations in Microsoft Flow

In this article, we will learn how to perform various SharePoint Group operations like create group, assign permissions to group, and add users to a group in Microsoft Flow.
As there is no SharePoint connector available to perform group operations in Microsoft Flow, we will be using different REST APIs. 
Step 1 - Create a flow
  • Visit here
  • Click My Flows from the left pane
  • Click on New flow on the right blade
  • Select instant blank as the template

1.png

 
 
Step 2
Name your flow and select trigger point as Manual trigger flow.
 
Step 3 - Create a group
  • Add action as 'Send HTTP request to SharePoint'. 
  • Select all configurable options as below.
URL
_api/web/SiteGroups  
Headers
1. accept
2. content-type 
application/json;odata=verbose  
Body
{  
"__metadata": {  
"type":"SP.Group"  
},  
"Title": "FlowGroup",  
"Description":"Group created from flow"  
} 
4.png
Step 4 
Before going to the next step, we would apply a simple trick for using data returned from the above request. Save this Flow and Run it once. Once the workflow has run successfully, go to flow history and copy the JSON response received in the above action (refer to the screenshot below). Go to the output section of the above action and copy the JSON. Keep it copied somewhere in the notepad; we will use it in the next step.
Also make sure you delete the group created, as we won't be checking condition if group exists or not. 
 
Step 5 
Add a new action, Parse JSON,
Content - Add body from dynamic content of above action
Schema - Click on 'Use sample payload to generate schema', paste the JSON copied in the previous step. 
4.png
Step 6
Add a new action 'Send HTTP request to SharePoint' and configure the action as below.
We would be using the below REST API to assign permissions to group.
/_api/web/roleassignments/addroleassignment(principalid=<GROUPID>, roledefid=1073741827)
roledefid for Permission Levels are as follows,
1073741829 - Full Control || 073741827 - Contribute || 1073741826 - Read
GroupID is the id of the group which we created from the step above. We will use dynamic content to form this URL by referencing group id.
 
Step 7
Add a new action 'Send HTTP request to SharePoint'; configure the action as below.
URI
_api/web/SiteGroups(<GroupID>)/users  
Headers - as mentioned in the below screenshot
Body
{  
   "__metadata": {  
   "type":"SP.User"  
   },  
"LoginName":"i:0#.f|membership|batman@dccomics.com"  
} 
Please note that the Login name should be in the exact format as above. You can always use dynamic content attribute which holds email id of a valid user (like I did in the below screenshot). Here, I am using dynamic content user email which will hold email id of the person who has triggered flow. You can modify this based on your requirements.
6.png
So, we are now done with our design; let us test the flow. Save it and test it from flow design.
7.png
Now let us go to Site collection-> Site Settings->People and Group, we can find FlowGroup named group in list.
8.png
Let us check what permission is assigned to this group, Click Settings-> View Group Permission (from above page)
We can see Permission level contribute is assigned to FlowGroup. 
9.png
In this article, we have learned and implemented the below 3 use cases.
  • Create a SharePoint Group
  • Assign Permission to SharePoint Group
  • Add user to SharePoint Group
Hope you enjoyed reading... Happy Flowing..!!!
P.S - This post was orginally published at this link.

 

Comments

hi @siddharth_v,

 

many thanks for the solution, very helpful.

 

please could you share a screenshot of 'Send an HTTP request to SharePoint - Assign Permission'?

 

best wishes and many thanks in advance,

 

p_m

Great read, and very helpful!

Great info. @siddharth_v!

I use the following to give rights to an existing O365 group:

ThomasDK_0-1645533995883.png

 

 


Roledefid for Permission Levels are as follows,
1073741829 - Full Control || 073741827 - Contribute || 1073741826 - Read

 


1073741827 instead of 073741827 - please correct, it took me 30 min to figure out what is wrong with flow.

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/