I'm trying to iterate over a dataset of SharePoint groups Id's, via the REST API, and process the results. The thing is, I don't have access to all the groups (this is expected). In this case, I'd like to log the group ID as "access denied" and move on to the next one.
When the code gets to the first group that I don't have access to, I'm prompted for credentials, as anticipated. Whether I enter cred's or just click "cancel" I I get the anticipated 401 error and the script just exits with-
HTTP401: DENIED - The requested resource requires user authentication.
(XHR)GET - https://{sourceSharePointSite}/_api/Web/SiteGroups/GetById({groupID})/Users
So, yes, I get the ID of the first group I don't have access to, but the script just exits and I really need to check the rest of the groups (more than 400 of them. don't ask)
Here's my code...
function getMultiGroupMembers(arrGroups){// arrGroups is an object defined earlier
$(arrGroups).each(function(i){
var myId = arrGroups.results[i].Id;
var myTitle = arrGroups.results[i].Title;
log("Group ID: "+myId+" Group Name: "+myTitle+ " Members:");
getData(myId).then(function() {
log( "getMultiGroupMembers success" );
}, function() {
log( "getMultiGroupMembers fail" );
})
});
}
function getData(groupId) {
var url = myUrl + "/_api/Web/SiteGroups/GetById("+groupId+")/Users";
return $.getJSON(url).then(function(data){
log("getGroupMembers() success: " + data);
arrUsers = jsonToCsv(data.d); // convert the JSON object to CSV for exporting
log(JSON.stringify(arrUsers)); // display the results in the log
}, function(err) {
var dfd = $.Deferred();
dfd.reject(err)
return dfd.promise();
})
}
Really not sure what I'm missing. I've tried in MS Edge and Chrome