3

I have a PHP application where I retrieve the documents from Sharepoint and display into a list where users can click to see/download the file. Currently I'm linking to the Sharepoint URL which is protected by login. I need to link to a link that can be accessed by anonymous users.

I can create a share link using the Sharepoint interface and I see in the network tab (google console) that a POST request to https://myclient.sharepoint.com/sites/CustomerPortal/_api/web/Lists(@a1)/GetItemById(@2)/ShareLink?@a1=%27%7B11CD851B%2D1385%2D43DA%2DBB41%2D132AFAAA0927%7D%27&@a2=%274620%27 is made. When I try to perform the same request via Postman I get the following error:

{
    "error": {
        "code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
        "message": {
            "lang": "en-US",
            "value": "The expression \"web/Lists(@a1)/GetItemById(@2)/ShareLink\" is not valid."
        }
    }
}

I tried to create an anonymous link using the endpoint: https://myclient.sharepoint.com/sites/CustomerPortal/_api/SP.Web.CreateAnonymousLink with the following JSON body:

{
    "url":"http://myclient.sharepoint.com/CustomerPortal/Folder/file.pdf",
    "isEditLink":"true"
}

and the response I get is:

{
    "error": {
        "code": "-1, System.InvalidOperationException",
        "message": {
            "lang": "en-US",
            "value": "Operation is not valid due to the current state of the object."
        }
    }
}

How can I create a anonymous link using REST API? Is it possible? Is there any configuration that my client needs to do on Sharepoint side?

Thank you.

0 Answers0