0

Very often Ajax is used to get list items, delete them, update them etc.

I want to know how I can use ajax to get the usernames of a specific SharePoint group. (Just printing them on the console is enough for me)

This is what I've got, but it doesn't work out, because it tells me The property "results" of an undefined or null reference could not be called. What am I doing wrong? I tried using DOM Explorer to look up the HTML as well and I was able to figure out in which div the username was written, but don't know what to write in the code.

function getSPGroupUserInfos() {

    NWF$.ajax({
            url: "sites/bm/_layouts/15/people.aspx?MembershipGroupId=9",
            type: "GET",
            headers:
               {
                   "Accept": "application/json;odata=verbose"
               },
            success: function (data, status, xhr) {
                console.log("dataresults: " + data.d.results);
                var dataresults = data.d.results;
                for (var i = 0; i < dataresults.length; i++) {
                console.log("User Title - " + dataresults[i].Title);
                }
            },
            error: function (xhr, status, error) {
                console.log("Failed");
            }
        });
}
1

1 Answer 1

1

Try using below SharePoint REST endpoint to get the group Members from specific group:

Considering name of your group is BM Members,

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

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

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

Check my full answer given at: REST API - Retrieve Group Members

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