Articles

How to create SharePoint group from flow

How to create SharePoint group from flow


In this article, We will see how to create a SharePoint group from Microsoft flow or Power Automate and assign permission to the group just created. So lets start by creating a mannually triggered flow.

 

Create a mannually triggered Flow

In order to create a mannually triggered flow, follow below steps.

  1. Go to https://flow.microsoft.com

  2. Click on My flows in left section

  3. Click new top and select Instant - from blank

  4. Choose mannually triggred flow and click Create

At this time your flow will be created. Now we need to add steps to create SharePoint group.

 

Create SharePoint group

In order to add SharePoint group follow below steps

1. Click Add new step and select send http request to SharePoint
2. Enter your site address
3. Uri : _api/web/SiteGroups
4. Add below two headers
accept :  application/json;odata=verbose 
content-type : application/json;odata=verbose 
5. Enter body as below
{  
"__metadata": {  
"type":"SP.Group"  
},  
"Title": "group name",  
"Description":"Group created for categories access" 
} 

 

this action will create group in SharePoin but this group will not have any access we need to make a REST call to 
/_api/web/roleassignments/addroleassignment(principalid=

So in order to add permission you need to have two things group id and role definition id

Role definition ids for permission levels are below


1073741829 - Full Control 
 073741827 - Contribute 
1073741826 - Read

Getting Group Id 

To get group id, We can parse the body of reponse of request we send to create the group. but to parse the response we need to have schema and luckly we have a way to get schema.
Just run the flow once and then go to run history and click on send request to SharePoint step and it will be expanded and then copy the json body of the response and have it some where.
 
Now return back to flow, and add a new step and choose parse json.
In body select body from send an HTTP request to SharePoint and in schema
Click generate from sample and paste the json copied in previous step and you are done.
 

Assign permission to created group

 Assigning permission to created group will be very easy. Add a "Send an HTTP request to SharePoint" step and bollow below steps
  1. In site address  add your address to site
  2. Coose method as POST
  3. Enter below uri 
  4.  /_api/web/roleassignments/addroleassignment(principalid=@{body('Parse_body_of_response')?['d']?['Id']}, roledefid=1073741826) 
     this should grant visitor permissions  
  5. add those two headers accept and content-type as entered while creating group.

You are done. test your flow by triggering mannualy and see how it works.

 

SharePoint Online
Microsoft Flow

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Mukesh Tiwari
Always ready to learn new technologies, A problem solver, exhibit to do attitude. Having around 10+ years of experience of development and management skills. I believe don't just set random goals but right goals suited for you.
Page Views :    Published Date : Jun 27,2020  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!