I am using SharePoint 2013 On-premise,
We have two SharePoint groups(Group-A, Group-B) in a SharePoint site. Group-A is owner group of Group-B, Generally Group-A users can add,delete users from Group-B.
when Group-A user trying to add a user to Group-B with following REST API code in button click, immediately a credentials popup is coming. when i checked the group B, user was added successfully.
Below is my code on button click. I am using Content editor web part.
function (webAbsoluteUrl, groupId, userLoginName, success, failure) {
var requestUri = webAbsoluteUrl + "/_api/web/sitegroups(" + groupId + ")/users"
var userDataItem = {
__metadata: {
type: 'SP.User'
},
LoginName: userLoginName
};
$.ajax({
url: requestUri,
type: "POST",
async: false,
data: JSON.stringify(userDataItem),
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: function (data) {
success(data);
},
error: function (data) {
failure(data);
}
});
}
Here my issue is::
- If Site-collection administrator login into the page, can able to add users to Group-B without any issues(no pop Up).
- Group-A user login into the page, can able add himself to Group-B without any issues(no pop Up).
- But Group-A user login into the page and trying to add other users to Group-B , User was added but immediately showing "SP Credentials pop-up".
I got following error in console::
"{"error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}"