cancel
Showing results for 
Search instead for 
Did you mean: 
Community Manager Community Manager
Community Manager

Create SharePoint Groups With Workflow

Jump to solution

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 ;)

 

 

Labels: (2)
0 Kudos
Reply
1 Reply
Community Manager Community Manager
Community Manager

Re: Create SharePoint Groups With Workflow

Jump to solution

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

Part1.png

 

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

ContextInfoWebRequest.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>

GetString.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

Part 2.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

RequestHeaders.png

 

Build Metadata:

type | Text | SP.Group

Output: Metadata

Metadata.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.

Parameters.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>

CreateGroup.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!

 

 

View solution in original post

0 Kudos
Reply