Create SharePoint Groups With Workflow

  • 28 January 2020
  • 1 reply
  • 8 views

Userlevel 5
Badge +19

Every once and a while we will get requests from customers on how to create SharePoint Groups with workflow in Office 365 given that this is no longer a native action function. While @TomaszPoszytek has a pretty good answer to this on a former post, I wanted to post up some detailed steps on exactly how this can be accomplished to help some future workflow builders ;)

 

 


1 reply

Userlevel 5
Badge +19

Creating a SharePoint group with the /_api/web/sitegroups call is a two step process:

  1.  Getting your ContextInfo security token
  2.  Make a web request to the sitegroups endpoint to create the group

 

Part 1: Getting your security token

6288i1AE6568D1631268B.png

 

The first step is making a call to the ContextInfo api with the Web Request action to get your Request Digest security token:

6289i1FD4E1216B11A2AC.png

Your web request should have the following configuration:

URL: {Workflow Context:Current site URL}‌/_api/contextinfo
Method: POST
Content type: application/x-www-form-urlencoded
Header name: Accept
Header Value: application/json;odata=verbose

Body: Content
{}
Username: <Username>
Password: <Password>

Store response content in: ContextInfo Response <Text Variable>

You will then want to extract out the actual token value from your call's response. There are a couple different ways that you can do this, but in my example I'm using the 'Extract Substring of String from Index with Length' action with the following configuration:

String: {Variable:ContextInfo Response}‌
Index: 134
Number of Characters: 157
Output: Digest Token <Text Variable>

6290i10EFF6B8AFE82D9D.png

 

If you'd like you can then log your 'Digest Token' variable to the history or send it in an email to validate that you're retrieving a valid token.

 

Part 2: Creating the SharePoint Group

6295iFD42A6491F2C4B5E.png

 

The second part of your workflow will actually create the SharePoint group. We will also do this with the Web Request action, however we will first need to build the appropriate headers, metadata and parameters for this request using the Build Dictionary action.

 

Build Request Header: 

Key | Type | Value

content-type | Text | application/json;odata=verbose
X-RequestDigest | Text | {Variable:Digest Token}‌
accept | Text | application/json;odata=verbose

Output: Request Headers

6291iE5395C62861C1FDE.png

 

Build Metadata:

type | Text | SP.Group

Output: Metadata

6292i0A85796776310329.png

 

Build Parameters: 

Key | Type | Value

__metadata | Dictionary | Variable:Metadata
Title | Text | <Group Name>
Description | <Group Description>

Output: Group Parameters // You can add additional group parameters if you'd like such as: AllowMembersEditMembership, AllowRequestToJoinLeave, AutoAcceptRequestToJoinLeave, etc. You can review the MSFT documentation to review all SP group parameters that are available.

6293iDC6ACBCAAD3EE76A.png

 

Now that we have our security token, headers, metadata, and parameters we can finally use the Web Request action to make our API call and create the SharePoint group:

URL: {Workflow Context:Current site URL}‌/_api/web/sitegroups
Method: POST
Content type: application/json;odata=verbose
Header name: x-RequestDigest
Header value: {Variable:Digest Token}‌
Body (Content): {Variable:Group Parameters}‌
Username: <Username>
Password: <Password>

Store response content in: Request Response Content <Text Variable>
Store http status code in: Response Status Code <Integer Variable>

6294i56EA2C43B55EEAF7.png

 

You can then log the response back to the workflow history, or send yourself an email with the response to ensure that it ran successfully!

 

Hope this helps, and be sure to check out other workflow templates within the new Process Accelerator Gallery!

 

 

Reply