1

I have a big need from a customer :

An external application needs to create folders and documents in a SharePoint Site.

Then, it will need to generate external links to share those documents to a vendor email address (which is external). User experience speaking, it is the "specific" settings, with email addresses : Copy link - Specific people setting

---EDIT : I edited this part to reflect that the application is registered and to not confuse people. --- The application is a registered application on the Azure Portal.

This application will send REST requests to create the folders and documents. But it will need to generate the link as well, using REST.

I found a lot different things, but no real endpoint using the REST API. (I don't want to generate an anonymous link, it would be a huge security breach).

Can you lead me to the right documentation maybe ? Thanks a lot !

5
  • Just a note, your application should really use an app registration for authentication instead of a user account (it's much safer from a security standpoint). Commented Aug 11, 2022 at 16:26
  • Thanks for the input @CallumCrowley, I don't know how I got you confused, but this is the case : the application is using an app registration :)
    – Gaelle
    Commented Aug 25, 2022 at 14:53
  • It's just where you're saying "The application will use a registered user (registered in AAD)". This is unclear, from that you could infer either that the application is using a "registered user" account to carry out tasks or that it's using delegated app permissions through an app registration. Commented Aug 25, 2022 at 14:57
  • @CallumCrowley, you're right, I just edited the question to reflect the situation better. Thanks again for your input !!!
    – Gaelle
    Commented Aug 25, 2022 at 15:08
  • No problem, glad to help. Commented Aug 25, 2022 at 15:09

1 Answer 1

3

There is no clear documentation provided by Microsoft for REST API for Sharing Document.

There is only one link which gives little bit details about what is the request model for passing details in API which I found. Rest of the detailed I covered it from Browser developer tools -> Network tab.

https://docs.microsoft.com/en-us/openspecs/sharepoint_protocols/ms-csomspt/50cd1911-fdc5-4e87-9a1d-29cf39f13ebd

REST API: _api/web/lists/getbytitle('{Document Library Title}')/getitembyid({Item ID})/sharelink

Request Type: POST

You need to add authentication token and request data digest into request. Below are helper links for it:

Call API: https://jeremythake.com/using-the-sharepoint-csom-and-rest-api-with-office-365-api-via-azure-ad-fe59a6d1a26

Get Request Digest using API: https://www.ozkary.com/2018/09/sharepoint-rest-api-post-with-token.html

Post Data:

I am sharing C# model which you can use to convert it JSON at the end

     public class ShareLinkRequestModel
    {
        public Request request { get; set; }
    }

    public class Request
    {
        public bool createLink { get; set; }
        public Settings settings { get; set; }
        public string peoplePickerInput { get; set; }
    }

    public class Settings
    {
        public SharingLinkKind linkKind { get; set; }
        public object expiration { get; set; }
        public Microsoft.SharePoint.Client.Sharing.Role role { get; set; }
        public bool restrictShareMembership { get; set; }
        public bool updatePassword { get; set; }
        public string password { get; set; }
        public Microsoft.SharePoint.Client.Sharing.SharingScope scope { get; set; }
    }

    public class PeoplePickerInputModel
    {
        public string Key { get; set; }
        public bool IsResolved { get; set; }
    }

Above API will work for both type of users i.e. Internal and External users.

Sample C# Code to do so for better understanding: https://github.com/kavaghela/sharedocumentspapi

Important: Make sure that External Sharing is enabled in your site in order to share content with external users. If you will share with external users which is not added in your tenant then while that external user will access shared document, Microsoft will do OTP verification (sent in email) to identify identity

How to enable External Sharing: https://docs.microsoft.com/en-us/sharepoint/change-external-sharing-site

1
  • Thanks a lot for your input @Kalpesh ! I'll try to make it work ! I don't undertand why I can't find any more documentation on the external sharing links, because it really is important. Especially as I don't want people to get anonymous link, even if they are externals, I want them to authenticate...
    – Gaelle
    Commented Aug 25, 2022 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.