4

We are using SharePoint Online. I am planning to add a flow to send out an email notification whenever a new page is added to the site.

To do that, I need the list of members of that site cause I don't want to send it to everyone or anyone.

I am unable to retrieve the group members through REST API. When I fire the following REST call, I am getting the response as follows, but not the actual members and their email addresses

https://dhdigitalcoin.sharepoint.com/sites/OpenSourceTechTalk/_api/web/sitegroups/getbyname('Open%20Source%20Tech%20Talk%20Members')/users


<entry>
<id>https://dhdigitalcoin.sharepoint.com/sites/OpenSourceTechTalk/_api/Web/GetUserById(7)</id>
<category term="SP.User" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link rel="edit" href="Web/GetUserById(7)"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Alerts" type="application/atom+xml;type=feed" title="Alerts" href="Web/GetUserById(7)/Alerts"/>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Groups" type="application/atom+xml;type=feed" title="Groups" href="Web/GetUserById(7)/Groups"/>
<title/>
<updated>2019-06-03T12:47:56Z</updated>
<author>
<name/>
</author>
<content type="application/xml">
<m:properties>
<d:Id m:type="Edm.Int32">7</d:Id>
<d:IsHiddenInUI m:type="Edm.Boolean">false</d:IsHiddenInUI>
<d:LoginName>c:0o.c|federateddirectoryclaimprovider|92b9f118-885e-4c23-a103-de7ce46d7421</d:LoginName>
<d:Title>Open Source Tech Talk Members</d:Title>
<d:PrincipalType m:type="Edm.Int32">4</d:PrincipalType>
<d:Email>[email protected]</d:Email>
<d:Expiration/>
<d:IsEmailAuthenticationGuestUser m:type="Edm.Boolean">false</d:IsEmailAuthenticationGuestUser>
<d:IsShareByEmailGuestUser m:type="Edm.Boolean">false</d:IsShareByEmailGuestUser>
<d:IsSiteAdmin m:type="Edm.Boolean">false</d:IsSiteAdmin>
<d:UserId m:null="true"/>
<d:UserPrincipalName m:null="true"/>
</m:properties>
</content>
</entry>

Is there a way I can retrieve the actual members?

Am I taking the right approach towards building email notifications?

2
  • Do you want to get all site users or users from particular SharePoint group?? Commented Jun 3, 2019 at 12:59
  • All site users.. Commented Jun 3, 2019 at 13:07

3 Answers 3

15

If you want to get all the users in your SharePoint site you can use :

/_api/web/siteusers?

Update:

Try using below endpoint to get the Site Members from Members group:

_api/Web/SiteGroups/GetByName('SiteName Members')/users

To get the specific property for user, you can add $select query as given below:

_api/Web/SiteGroups/GetByName('SiteName Members')/users?$select=Email,Id

You can get the following user properties using this endpoint:

  1. Email
  2. Groups
  3. Id
  4. IsHiddenInUI
  5. IsSiteAdmin
  6. LoginName
  7. PrincipalType
  8. Title
  9. UserId

You can find everything related to Users, groups, and roles using REST API in below article(Must visit, this is a very helpful article): Users, groups, and roles using REST API.

11
  • When I fire this, I am getting the email addresses of visitors as well.. which I don't want.. Commented Jun 3, 2019 at 13:09
  • try using members group...group name will be like SiteName<space>Members. Commented Jun 3, 2019 at 13:15
  • Have you tried this?? Commented Jun 3, 2019 at 13:37
  • I am using the members group only.. And When I fire your updated result, it is indeed selecting only the email address but it is still not giving me the individual members. Instead, it is just returning the email [email protected] Commented Jun 4, 2019 at 9:59
  • have you used /users? You can go the group you want to fetch and check if any users are added there. Commented Jun 4, 2019 at 10:12
0

You are getting back the actual users, just not their email address. You need to select Email, like:

_spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getbyname('Open%20Source%20Tech%20Talk%20Members')/users?$select=Email"

This will get back a response like:

{
    value: [
        0: {
               Email: "[email protected]"
        },
        length: 2
    ]
}

assuming you set an accept header like:

headers: {
    'accept': 'application/json;odata=nometadata'
}
2
  • The issue is that the users are not the ones who are members of the group. There are actually two users as members of the group and sharepoint is returning only one entry which is again with a grouped email address. Commented Jun 4, 2019 at 10:00
  • 1
    Ok, I did misunderstand your problem a bit, but what you want is something I've been looking for since 2007 and it just doesn't exist, at least not in SharePoint. You'd need a SharePoint API that expands the AD security group, and there isn't one. If there is a way to expand a group by talking directly to AD from flow, that would be the way to go, but using the SharePoint APIs there is no way to tell what users are members of a SharePoint group indirectly (i.e. granted through membership in an AD security group).
    – Joe McShea
    Commented Jun 5, 2019 at 18:09
0

Just to keep an extra piece of information, since I can't add comments yet.

Here is a guide I have followed, which unfortunately though throws an error at some point due to mismatch between the JSON and the scheme.

https://www.intelogy.co.uk/blog/assigning-microsoft-flow-approvals-to-sharepoint-groups/

I think this can be solved by retrieving the JSON once and then pasting it to the Parser in order to re-create the correct schema, but following the solutions above (kudos to Joe McShea and Ganesh Sanap), as to pre-filter looking only for the email of users makes it way easier!

Just use the following as an HTTP GET request to Sharepoint:

_api/web/sitegroups/getbyname('Open%20Source%20Tech%20Talk%20Members')/users?$select=Email"

add the accept headers as mentioned above and use the following as a schema when you need to Parse the JSON

    {
    "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"
                                    }
                                }
                            },
                            "Email": {
                                "type": "string"
                            }
                        },
                        "required": [
                            "__metadata",
                            "Email"
                        ]
                    }
                }
            }
        }
    }
}

Then you can create an array with all the emails to use in your Approval.

It works fine with a custom Sharepoint group in the site when members are added individually. I have not tested if you can invite AD groups and get the members too, if that's what you are looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.