cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
golfnutt82
Super User
Super User

Creating a SP Group Using Power Automate and REST API

Hello,
I found a resource that explains how to create a SharePoint group using Send an HTTP Request and Parse JSON.
However, when I use this, a new SP Group(s) is not created.
Any help would be appreciated.

golfnutt82_1-1630419151103.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Super User
Super User

Hi @golfnutt82,

 

1. To check if the SharePoint group already exists you can use a filter with the Title with a GET request. If the response is empty your group doesn't exist yet.

 

 

_api/Web/SiteGroups/?$filter=Title eq '@{variables('SharePointGroupName')}'

 

 

getsitegroups.png

 

2. To add a user you can use a POST request against the specific site group.

Make sure you use the correct claim of the user.

 

 

_api/web/sitegroups/GetByName('@{variables('SharePointGroupName')}')/Users

 

 

 

{  
    '__metadata': {  
        'type': 'SP.User'  
    },  
    'LoginName': '@{variables('UserClaim')}' 
}

 

 

addusertogroup.png

 

3. When the site already has unique permissions you can use the addroleassignment method with a POST request to assign permissions to your new or existing group.

In the example below I am using contribute permission. Also make sure you use the correct principalid of the SharePoint group.

 

 

_api/web/roleAssignments/addroleassignment(principalId=@{variables('Id')}, roledefId=1073741827)

 

 

grantcontributepermissiontogroup.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


View solution in original post

10 REPLIES 10
Expiscornovus
Super User
Super User

Hi @golfnutt82,

 

Can you switch the method from GET to POST? 



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


I tried Post and it hung forever.

Expiscornovus
Super User
Super User

Hi @golfnutt82,

 

Did you try it with the same title and description in the body of the request from your first screenshot?

 

If so, can you try a different title (e.g. FlowGroup2)? It looks like the SharePoint group with title FlowGroup already exists (looking at the get GET response from your first screenshot).



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


I tried changing it to "FlowGroup1" ran it but I still dont see a created group.

golfnutt82_0-1630431814142.png

 

I think I know what the issue but I am not sure so maybe you can clear things up for me.
Where the URI is I entered per the instruction 

golfnutt82_1-1630497641614.png

Because I am working from withing a sub-site having unique permissions from the parent should the URL look different? I am concerned that I created the group(s) at the top level.

golfnutt82_2-1630497819385.png

 

Expiscornovus
Super User
Super User

Hi @golfnutt82,

 

You are looking at the assigned permissions. We haven't assigned any permission level (e.g. read, edit or full control) to this group yet. That is why it isn't shown in the site permissions overview.

 

If you want to see the group itself you could navigate to the People and Groups overview of the sub-site. That should be accessible via this url:

/sites/Test-IT/SecTest/SecTest1/_layouts/15/groups.aspx



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Ahh, I see. Yes the group was created but now I want to assign the group permissions and then add users.
I appreciate your help.

I just thought of something; what if the group is already created? Can I check this condition and then just add the user to the existing group?

Expiscornovus
Super User
Super User

Hi @golfnutt82,

 

1. To check if the SharePoint group already exists you can use a filter with the Title with a GET request. If the response is empty your group doesn't exist yet.

 

 

_api/Web/SiteGroups/?$filter=Title eq '@{variables('SharePointGroupName')}'

 

 

getsitegroups.png

 

2. To add a user you can use a POST request against the specific site group.

Make sure you use the correct claim of the user.

 

 

_api/web/sitegroups/GetByName('@{variables('SharePointGroupName')}')/Users

 

 

 

{  
    '__metadata': {  
        'type': 'SP.User'  
    },  
    'LoginName': '@{variables('UserClaim')}' 
}

 

 

addusertogroup.png

 

3. When the site already has unique permissions you can use the addroleassignment method with a POST request to assign permissions to your new or existing group.

In the example below I am using contribute permission. Also make sure you use the correct principalid of the SharePoint group.

 

 

_api/web/roleAssignments/addroleassignment(principalId=@{variables('Id')}, roledefId=1073741827)

 

 

grantcontributepermissiontogroup.png



Happy to help out! 🙂

Interested in more #PowerAutomate #SharePointOnline or #PowerVirtualAgents content?
Visit my blog, Subscribe to my YouTube channel or Follow me on Twitter


Thank you very much for these details!
Extremely grateful for your assistance.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Users online (2,723)