Each SharePoint site is associated with three SharePoint groups: Owners, Members, and Visitors. And the SharePoint site is also enabled to share with other users or external users.
Due to security reasons, sharing is mostly disabled for anyone other than owners. In this post, we are going to validate whether users who have member permission can have access to share the site or not.
The below REST API format will help to validate that,
https://domain.sharepoint.com/_api/web?$select=MembersCanShare
The response value returns true if the members have access to share the SharePoint Site and its folders/files. It returns false when members don’t have that permission.
The Sharing permissions can be managed from the SharePoint Site Permissions panel.
To test this using REST API in the browser instantly, navigate to the SharePoint site. Then open the browser’s web console and paste the below snippet,
-
-
- function getRequest(url) {
- var request = new XMLHttpRequest();
- return new Promise(function(resolve, reject) {
- request.onreadystatechange = function() {
- if (request.readyState !== 4) return;
- if (request.status >= 200 && request.status < 300) {
- resolve(request);
- } else {
- reject({
- status: request.status,
- statusText: request.statusText
- });
- }
- };
-
- request.open('GET', url, true);
- request.setRequestHeader("Content-Type", "application/json;charset=utf-8");
- request.setRequestHeader("ACCEPT", "application/json; odata.metadata=minimal");
- request.setRequestHeader("ODATA-VERSION", "4.0");
- request.send();
-
- });
- }
-
-
- getRequest("https://domain.sharepoint.com/_api/web?$select=MembersCanShare").then(function(output) {
- var result = JSON.parse(output.response);
- if (result.MembersCanShare){
- alert("Members can share this site and its folder & files");
- }else{
- alert("Members do not have permission to share this site!");
- }
- });
-