Validate If Current User Can Create Office 365 Group In SharePoint

Office 365 Groups can be created across different services in Office 365, even though each service will check if the current user has the permission to create an Office 365 group or not. In this post, we will see how to validate if the current user has permission to create an Office 365 group using SharePoint Online REST API.
 
The below REST API format will help to identify that:
 
https://domain.sharepoint.com/_api/GroupSiteManager/CanUserCreateGroup
 
This returns the result in a Boolean value. If the current user has permission to create Office 365 group, the result would be true. And if it returns false, the current user couldn’t create a new Office 365 Group.
 
To test this, navigate to the SharePoint site. Then open the browser’s web console and paste the below code snippet.
  1. //getRequest method reference  
  2. //https://gist.github.com/ktskumar/a9e9df497673e9fd26ead8532b9ff425  
  3. function getRequest(url) {  
  4.     var request = new XMLHttpRequest();  
  5.     return new Promise(function(resolve, reject) {  
  6.         request.onreadystatechange = function() {  
  7.             if (request.readyState !== 4) return;  
  8.             if (request.status >= 200 && request.status < 300) {  
  9.                 resolve(request);  
  10.             } else {  
  11.                 reject({  
  12.                     status: request.status,  
  13.                     statusText: request.statusText  
  14.                 });  
  15.             }  
  16.         };  
  17.   
  18.         request.open('GET', url, true);  
  19.         request.setRequestHeader("Content-Type""application/json;charset=utf-8");  
  20.         request.setRequestHeader("ACCEPT""application/json; odata.metadata=minimal");         
  21.         request.setRequestHeader("ODATA-VERSION""4.0");  
  22.         request.send();  
  23.   
  24.     });  
  25. }  
  26.   
  27. //Modify domain.sharepoint.com with your SharePoint site URL  
  28. getRequest("https://domain.sharepoint.com/_api/GroupSiteManager/CanUserCreateGroup").then(function(output) {  
  29.     var result = JSON.parse(output.response);  
  30.     if (result.value){  
  31.       alert("The current user can create Office 365 Group!");  
  32.     }else{  
  33.       alert("The current user do not have permission to create Office365 Group!");  
  34.     }      
  35. });  
  36.   
  37. //Reference: https://gist.github.com/ktskumar/458e1c9d46038078470f3a1d9935fdbe