Office 365 SharePoint 2013 Online Get GroupID Using REST API

To use the example in this blog, you'll need
  1. A SharePoint 2013 development environment (app isolation required for On-Premises scenario).
  2. Visual Studio 2012 or Visual Studio 2013 with Office Developer tools for Visual Studio 2012
  3. Napa (SharePoint Online only).
  4. You'll also need to set full control add-in permissions at the Web scope. Only the users who have sufficient permissions to change list permissions (such as site owners) can run this add-in.
  1. var siteUrl = 'http://gowthamr.SharePoint.com';  
  2. var listTitle = 'Tutorial List';  
  3. var groupName = 'Gowthamr Owners';  
  4. var targetRoleDefinitionName = 'Contribute';  
  5. var groupId;  
  6. var targetRoleDefinitionId;  
  7.   
  8. $(document).ready( function() {  
  9.     getTargetGroupId();  
  10. });  
  11.   
  12.   
  13. function getTargetGroupId() {  
  14.     $.ajax({  
  15.         url: siteUrl + '/_api/web/sitegroups/getbyname(\'' + groupName + '\')/id',  
  16.         type: 'GET',  
  17.         headers: { 'accept':'application/json;odata=verbose' },  
  18.         success: successHandler(responseData),                 
  19.         error: errorHandler  
  20.    });  
  21. }  
  22. function successHandler(responseData) {  
  23.             groupId = responseData.d.Id;  
  24.             getTargetRoleDefinitionId();  
  25.     alert('Request succeeded Successfully.');  
  26. }   
  27.   
  28. function errorHandler(xhr, ajaxOptions, thrownError) {  
  29.     alert('Request failed: ' + xhr.status + '\n' + thrownError + '\n' + xhr.responseText);  
  30. }  
Was my blog helpful?

If so, please let us know at the bottom of this page. If not, let us know what was confusing or missing and I’ll use your feedback to double-check the facts, add info and update this blog.
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now