I am trying to add a webpart that will be able to share several different types of items in SharePoint 2013 OnPremises. I am using the following code, which seems to work well with one exception.
function shareDocSet(){
var restSource = "http://sharepointsite.com/sites/siteName/_api/SP.Sharing.DocumentSharingManager.UpdateDocumentSharingInfo";
$.ajax(
{
'url': restSource,
'method': 'POST',
'dataType': 'text',
'data': JSON.stringify({
'resourceAddress': 'http://sharepointsite.com/sites/siteName/Lists/Custom List/Test1',
'userRoleAssignments': [{
'__metadata': {
'type': 'SP.Sharing.UserRoleAssignment'
},
'Role': 2,
'UserId': 'i:0#.w|domain\\john.smith'
}],
'validateExistingPermissions': true,
'additiveMode': true,
'sendServerManagedNotification': false,
'customMessage': "Please look at the following folder",
'includeAnonymousLinksInNotification': false
}),
'headers': {
'content-type': 'application/json;odata=verbose',
'X-RequestDigest': $('#__REQUESTDIGEST').val(),
'Accept': 'application/json;odata=verbose'
},
'success': function (data) {
var d = data;
console.log("Success!");
},
'error': function (err) {
console.log(JSON.stringify(err));
}
}
);
}
This code successfully shares all items in a document library(Folders, DocSets, and Documents) as well as list items in a custom list. However it does not share Folders in a custom list where folders have been enabled. When I try to share one of these folders I get a success callback but it just returns an empty results array in the UpdateDocumentSharingInfo object, where I would expect to see the user and the role they have been given. Checking the folder in question indicates that inheritance has not been broken on the item and the user has not been granted access. The only possible explaination I can think of is maybe there is some additional property I need to enable on a list before I can share folders?