Wednesday, 28 March 2018

Share a Document using Rest API

function shareDocumentWithOtherUsers()
{
  //  var hostweburl = decodeURIComponent('https://cbcd.sharepoint.com');
   // var appweburl = decodeURIComponent('https://abcd.sharepoint.com/sites/ssss/vvvv');
    var restSource = myCompanyUrl + "/_api/SP.Sharing.DocumentSharingManager.UpdateDocumentSharingInfo";
    $.ajax(
    {
        'url': restSource,
        'method': 'POST',
        'data': JSON.stringify({
            'resourceAddress': 'https://abcd.sharepoint.com/sites/ssss/vvvv/LibraryName/Before%20you%20ca%20djshjd.png',
            'userRoleAssignments': [{
                '__metadata': {
                    'type': 'SP.Sharing.UserRoleAssignment'
                },
                'Role': 1,
                'UserId': 'aaaa.ssss@ddddd.com'
            }],
            'validateExistingPermissions': false,
            'additiveMode': true,
            'sendServerManagedNotification': true,
            'customMessage': "Please look at the following document",
            'includeAnonymousLinksInNotification': true
        }),
        'headers': {
            'accept': 'application/json;odata=verbose',
            'content-type': 'application/json;odata=verbose',
            'X-RequestDigest': $('#__REQUESTDIGEST').val()
        },
        'success': function (data) {
            var d = data;
            console.log(d);
        },
        'error': function (err)
        {
            alert(JSON.stringify(err));
        }
    });
}

No comments:

Post a Comment