What is the REST API endpoint that i can use share a file with external users using "People you chose"

john john 946 Reputation points
2023-05-11T22:46:46.22+00:00

Inside the UI we can share a file with external users using "People you chose":-

User's image

So is there an equivalent end point in SharePoint REST API which allow me >> to send a sharing link to external users by email + with Read-only permission (which mimic the functionalities in the above picture)?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,733 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,685 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. ChengFeng - MSFT 5,010 Reputation points Microsoft Vendor
    2023-05-12T08:26:29.8333333+00:00

    Hi @john john ,

    Do you want to simulate the UI interface, send file sharing links to external people through flow, and only have read-only permissions?

    Here is a test for your reference:

    Create a file in the folder:

    User's image

    User's image

    __

    First, Create a flow and set manual triggers:

    User's image

    Second,you need to obtain an access token to authenticate your request. You can do this by using the "Send an HTTP request to SharePoint" action with the following configuration:

    Method: POST 

    Uri: _api/contextinfo

    Headers: Accept: application/json;odata=nometadata

    User's image

    Next, you can use the following API endpoint to create a sharing link with read-only permission for external users:

    Method: POST

    Uri: _[api/web/lists('your]/GetItemByID('youritemid')/sharelink

    Headers:

    Accept: application/json;odata=nometadata
    Content-Type: application/json;odata=nometadata
    X-RequestDigest: [YourAccessToken]
    

    (In power automate, we can use the formula to get the fields we need in the returned content)

    Here is the body of a request to create a shared link, where:

    User's image

    {
    "request":{
    "createLink":true,
    "settings":{
    "allowAnonymousAccess":true,
    "linkKind":3,
    "role":0,
    "restrictShareMembership":false,
    "scope":0
    },
    }
    }
    

    createLink :specifies whether to create a shared link, here set to true means to create.

    allowAnonymousAccess :specifies whether to allow anonymous access, here set to true means to allow.

    linkKind  : Specifies the type of shared link, here setting it to 3 means generating a link that can be sent by email.

    role :specifies the role of the shared link, here it is set to 0 for read-only permission.

    restrictShareMembership : specifies whether to restrict the members of the shared link, here set to false means no restriction.

    scope :specifies the scope of the shared link, here setting it to 0 means the link is visible to everyone.

    Finally, Send the email.

    Please use the formula to dynamically obtain the sharelink in the content returned by the above request

    Sharelink: body('Send_an_HTTP_request_to_SharePoint_2')?['sharingLinkInfo/Url']

    Send emails in the form of <a>, and you can also customize the content of the email

    User's image

    Here is result:

    User's image

    User's image

    I hope this helps you solve your problem!

     


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

     

    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.

     

    Best Regards

    Cheng Feng


  2. john john 946 Reputation points
    2023-05-12T11:25:15.39+00:00

    thanks for you reply ,, but in my case i do not want to create anonymous link i want to create a link shared with specific users which mimic the options to send sharing link to "People you choose" inside the UI, so should i use

    "allowAnonymousAccess":false,
    

    instead of

    "allowAnonymousAccess":true,
    
    
    

    and what are the different options we have for the LinkKind and for the Role paramters?


  3. Luciano Claudino Barbosa 0 Reputation points
    2023-11-17T20:41:59.49+00:00
    Hi, with the application registered, I can upload the file but I cannot share it (/sharelink), where I receive the error below (403 forbidden), has anyone experienced this problem?
    
    {
        "odata.error": {
            "code": "-2147024891, System.UnauthorizedAccessException",
            "message": {
                "lang": "pt-BR",
                "value": "Attempted to perform an unauthorized operation."
            }
        }
    }
    
    0 comments No comments