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

View solution in original post

10 REPLIES 10
Expiscornovus
Super User
Super User

Hi @golfnutt82,

 

Can you switch the method from GET to POST? 

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

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

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

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

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Users online (3,082)