使用REST api创建Sharepoint匿名链接

时间:2018-05-14 07:49:01

标签: sharepoint sharepoint-api

我有一个PHP应用程序,我从Sharepoint检索文档并显示到用户可以单击以查看/下载文件的列表。 目前我正在链接到受登录保护的Sharepoint URL。我需要链接到匿名用户可以访问的链接。

我可以使用Sharepoint界面创建共享链接,并在网络选项卡(谷歌控制台)中看到发出了对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的POST请求。 当我尝试通过Postman执行相同的请求时,我收到以下错误:

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

我尝试使用端点创建匿名链接:https://myclient.sharepoint.com/sites/CustomerPortal/_api/SP.Web.CreateAnonymousLink 使用以下JSON正文:

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

我得到的回应是:

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

如何使用REST API创建匿名链接?可能吗?我的客户端是否需要在Sharepoint端进行任何配置?

谢谢。

0 个答案:

没有答案