I am trying to create a SharePoint Group in a SharePoint Add-in, which has Full Control over the site collection, using JSOM. Here is my code:

    function createGroup(groupName) {

        var hostUrl = decodeURIComponent(GetUrlKeyValue('SPHostUrl').split(',')[0]);

        var ctx = new SP.ClientContext(hostUrl);
        var site = ctx.get_site();
        var oWeb = site.get_rootWeb();

        var groupCreationInfo = new SP.GroupCreationInformation();
        groupCreationInfo.set_description('Contributor group.');

        var oGroup = oWeb.get_siteGroups().add(groupCreationInfo);

        var roleDefinitionBindingColl = SP.RoleDefinitionBindingCollection.newObject(ctx);

        var oRoleDefinition = oWeb.get_roleDefinitions().getByType(SP.RoleType.contributor);

        oWeb.get_roleAssignments().add(oGroup, roleDefinitionBindingColl);

        Function.createDelegate(this, function (sender, args) {
        Function.createDelegate(this, function (sender, args) {


When the code runs, I get the following error:

enter image description here

Any help or advice on how to add a SharePoint Group via JSOM in a SharePoint Add-in would be much appreciated.

  • 1
    The problem was that I had given the app full control over the site collection in the app manifest and didn't go into Manage Permissions in the site collection for the app and click "Trust It" again. This step is required after every deployment. – GW - SharePoint Developer Jan 23 '16 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.