cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular Visitor

How to get Groups names of SharePoint sites

Hello everyone,

I am looking for a list of groups in a SharePoint site, I know there is the "HTTP request to SharePoint" connector with the code "/_api/web/sitegroups/getbyname('groupname')/users." but that is the problem.

In my project I am not supposed to know the "getbyname('groupname') and since it is an automation stream, I will not go to the site and look for the names of these groups myself.

The goal is that the flow itself will discover the names of the groups in a SharePoint site with a connector, but I never found the answer.

Could you please help me?

Sincerely.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Hi @Bucheron 

 

If you want to retrieve all group names it is probably easier to add a parse json action and than loop through the results of that parse json output results.

 

1. Add a parse json action. Use the body of your http request to sharepoint action and use the following schema

{
    "type": "object",
    "properties": {
        "d": {
            "type": "object",
            "properties": {
                "results": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "__metadata": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "uri": {
                                        "type": "string"
                                    },
                                    "type": {
                                        "type": "string"
                                    }
                                }
                            },
                            "Owner": {
                                "type": "object",
                                "properties": {
                                    "__deferred": {
                                        "type": "object",
                                        "properties": {
                                            "uri": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            },
                            "Users": {
                                "type": "object",
                                "properties": {
                                    "__deferred": {
                                        "type": "object",
                                        "properties": {
                                            "uri": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            },
                            "Id": {
                                "type": "integer"
                            },
                            "IsHiddenInUI": {
                                "type": "boolean"
                            },
                            "LoginName": {
                                "type": "string"
                            },
                            "Title": {
                                "type": "string"
                            },
                            "PrincipalType": {
                                "type": "integer"
                            },
                            "AllowMembersEditMembership": {
                                "type": "boolean"
                            },
                            "AllowRequestToJoinLeave": {
                                "type": "boolean"
                            },
                            "AutoAcceptRequestToJoinLeave": {
                                "type": "boolean"
                            },
                            "Description": {},
                            "OnlyAllowMembersViewMembership": {
                                "type": "boolean"
                            },
                            "OwnerTitle": {
                                "type": "string"
                            },
                            "RequestToJoinLeaveEmailSetting": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "__metadata",
                            "Owner",
                            "Users",
                            "Id",
                            "IsHiddenInUI",
                            "LoginName",
                            "Title",
                            "PrincipalType",
                            "AllowMembersEditMembership",
                            "AllowRequestToJoinLeave",
                            "AutoAcceptRequestToJoinLeave",
                            "Description",
                            "OnlyAllowMembersViewMembership",
                            "OwnerTitle",
                            "RequestToJoinLeaveEmailSetting"
                        ]
                    }
                }
            }
        }
    }
}

parsejson_sitegroups.png

 

2. Add the results to an apply for each and add for instance a compose within the apply to each to display the loginname field

results_sitegroupsparsejson.png

 

View solution in original post

4 REPLIES 4
Super User II
Super User II

Hi @Bucheron,

 

You can remove the last part (getbyname('groupname')/users) of your code to collect the sitegroups. 

 

Below is an example to get the LoginName of the first group.

 

1. Add a Send an HTTP request to SharePoint action and use the following value for the URI field:

_api/web/sitegroups

 

http_sitegroups.png

2. In my example I am using a compose and an expression to extract the LoginName of the first group. 

outputs('Send_an_HTTP_request_to_SharePoint')?['body']['d']['results'][0]['LoginName']

firstsitegroupname.png

 

Hope this helps a bit to get you started?

 

Regular Visitor

Thanks my savior

I managed with your code to get the name of the first group.

Is there a way to tell it to retrieve all existing LoginName on the site by retrieving the number of IDs that exist on the site to replace the [0] through a loop?

Or is there a simpler way out of my understanding? ^^

Super User II
Super User II

Hi @Bucheron 

 

If you want to retrieve all group names it is probably easier to add a parse json action and than loop through the results of that parse json output results.

 

1. Add a parse json action. Use the body of your http request to sharepoint action and use the following schema

{
    "type": "object",
    "properties": {
        "d": {
            "type": "object",
            "properties": {
                "results": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "__metadata": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "uri": {
                                        "type": "string"
                                    },
                                    "type": {
                                        "type": "string"
                                    }
                                }
                            },
                            "Owner": {
                                "type": "object",
                                "properties": {
                                    "__deferred": {
                                        "type": "object",
                                        "properties": {
                                            "uri": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            },
                            "Users": {
                                "type": "object",
                                "properties": {
                                    "__deferred": {
                                        "type": "object",
                                        "properties": {
                                            "uri": {
                                                "type": "string"
                                            }
                                        }
                                    }
                                }
                            },
                            "Id": {
                                "type": "integer"
                            },
                            "IsHiddenInUI": {
                                "type": "boolean"
                            },
                            "LoginName": {
                                "type": "string"
                            },
                            "Title": {
                                "type": "string"
                            },
                            "PrincipalType": {
                                "type": "integer"
                            },
                            "AllowMembersEditMembership": {
                                "type": "boolean"
                            },
                            "AllowRequestToJoinLeave": {
                                "type": "boolean"
                            },
                            "AutoAcceptRequestToJoinLeave": {
                                "type": "boolean"
                            },
                            "Description": {},
                            "OnlyAllowMembersViewMembership": {
                                "type": "boolean"
                            },
                            "OwnerTitle": {
                                "type": "string"
                            },
                            "RequestToJoinLeaveEmailSetting": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "__metadata",
                            "Owner",
                            "Users",
                            "Id",
                            "IsHiddenInUI",
                            "LoginName",
                            "Title",
                            "PrincipalType",
                            "AllowMembersEditMembership",
                            "AllowRequestToJoinLeave",
                            "AutoAcceptRequestToJoinLeave",
                            "Description",
                            "OnlyAllowMembersViewMembership",
                            "OwnerTitle",
                            "RequestToJoinLeaveEmailSetting"
                        ]
                    }
                }
            }
        }
    }
}

parsejson_sitegroups.png

 

2. Add the results to an apply for each and add for instance a compose within the apply to each to display the loginname field

results_sitegroupsparsejson.png

 

View solution in original post

Regular Visitor

Thank you very much.

I just have to do more tests for different uses but this base is already solid, again thanks.

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

Microsoft Ignite

Microsoft Power Platform: 2021 Release Wave 1 Plan

Power Platform release plan for the 2021 release wave 1 describes all new features releasing from April through September 2021.

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (17,596)