user545359
user545359

Reputation: 413

Get SharePoint group permissions level name based on group name Using SharePoint Rest API

I am trying to get SharePoint User group permissions (Ex: Read, Contribute) based on the group name using SharePoint Rest API. My goal is to get the permission level of the group and disable features on our custom app based on the permission levels. I have tried the below url to get the group properties but couldn't get the permission level of the group. Could anyone please guide me on how to get the User group permissions.

Options Tried:

URL = http://Servename/Site/api/web/SiteGroups/getByName('group name')

Upvotes: 0

Views: 3506

Answers (2)

Shahid Iqbal
Shahid Iqbal

Reputation: 1

The function below returns Group Permission Level title and rest of the information:

function init() {       
    clientContext = new SP.ClientContext.get_current();
    oWeb = clientContext.get_web();
    currentUser = oWeb.get_currentUser();
    allGroups = currentUser.get_groups();
    clientContext.load(allGroups);

    clientContext.executeQueryAsync(OnSuccess, OnFailure);
    function OnSuccess() {
        var grpsEnumerator = allGroups.getEnumerator();

        while (grpsEnumerator.moveNext()) {         
        var group = grpsEnumerator.get_current();
        var grpTitle = group.get_title();
        var grpid = group.get_id();
        console.log('Group Id :' + grpid);
        console.log('Group Title :'+ grpTitle);

        roleBindings = oWeb.get_roleAssignments().getByPrincipalId(grpid).get_roleDefinitionBindings();
        clientContext.load(roleBindings);

            clientContext.executeQueryAsync(function () {
                var iterator = roleBindings.getEnumerator();
                while (iterator.moveNext()) {
                    current = iterator.get_current();
                    console.log('Show Role Defination Title : '+ current.get_name());

                    }
            });
        }
    }

    function OnFailure(){
    console.log('Process Failed');
    }
}

Upvotes: 0

Verthosa
Verthosa

Reputation: 1688

You won't be able to get this from the SiteGroup object alone. Your rest-call only retrieves group information (title, id, description and other metadata). To retrieve permission levels you will need to do a couple of more calls. See https://msdn.microsoft.com/en-us/library/office/dn531432.aspx to read more about RoleAssignment and RoleDefinition

Upvotes: 0

Related Questions