I don't know.
Sharepoint REST API - share document
Hi,
Does anyone knows how to use REST API to share a document in sharepoint to someone inside the same organization and external user ?
Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office SharePoint Server Development
2 answers
Sort by: Most helpful
-
-
RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
2021-08-16T06:26:25.17+00:00 Hi @Alvin ,
Below is the REST call using JavaScript code that shares a document from a SharePoint hosted app:function shareDocument() { var hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl')); var appweburl = decodeURIComponent(getQueryStringParameter('SPAppWebUrl')); var restSource = appweburl + "/_api/SP.Sharing.DocumentSharingManager.UpdateDocumentSharingInfo"; $.ajax( { 'url': restSource, 'method': 'POST', 'data': JSON.stringify({ 'resourceAddress': 'documenturl', 'userRoleAssignments': [{ '__metadata': { 'type': 'SP.Sharing.UserRoleAssignment' }, 'Role': 1, 'UserId': 'Chris Tester' }], 'validateExistingPermissions': false, 'additiveMode': true, 'sendServerManagedNotification': false, 'customMessage': "Please look at the following document", 'includeAnonymousLinksInNotification': false }), 'headers': { 'accept': 'application/json;odata=verbose', 'content-type': 'application/json;odata=verbose', 'X-RequestDigest': $('#__REQUESTDIGEST').val() }, 'success': function (data) { var d = data; }, 'error': function (err) { } } ); }
UserRoleAssignments: This an array of users and roles that you want to share the document with. The Role property represents which permission you are assigning. 1 = View, 2 = Edit, 3 = Owner, 0 = None.
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.