【问题标题】:Error creating communication site in Sharepoint Online via REST and Javascript通过 REST 和 Javascript 在 Sharepoint Online 中创建通信站点时出错
【发布时间】:2018-03-14 21:08:52
【问题描述】:

我正在尝试基于通信网站模板创建一个共享点在线网站集,如 Microsoft 在此处 https://docs.microsoft.com/en-us/sharepoint/dev/apis/communication-site-creation-rest 中所述,通过在不同共享点网站的页面上使用 javascript

但是,我不断收到 403 的响应——尽管我是租户管理员,因此绝对有权创建站点。 我正在从诸如 companyname.sharepoint.com/sites/myTestSite/sitepages/RunSomeJS.aspx 之类的 url 的页面运行下面的脚本

我已尝试指定两者的 REST 端点域 公司名称.sharepoint.com 和 公司名称-admin.sharepoint.com 但得到同样的错误。

function DoRestCall(){      
    var body={'parameters':
    {
        "__metadata":{"type":"SP.Publishing.CommunicationSiteCreationRequest"},
        "AllowFileSharingForGuestUsers":false,
        "Classification":"MyTest Communication Site",
        "Description":"Here is my communication site",
        "SiteDesignId":"6142d2a0-63a5-4ba0-aede-d9fefca2c767",
        "Title":"MyTest Communication Site",
        "Url":"https://companyname.sharepoint.com/sites/testSiteName",            
        "lcid":1033
        }
    };
    $.ajax({
        type: 'POST',
        url: "https://companyname.sharepoint.com/_api/sitepages/create",
        contentType: 'application/json',
        processData: false,
        headers:{
            "accept":"application/json;odata=verbose",
            "content-type":"application/json;odata=verbose",
            "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
        },
        data: JSON.stringify(body),
        success: function () 
        {
            alert('CREATION REQUEST SUBMITTED');
        },
        error: function(data){
            alert('failure:' + data.statusText );
        }
    });
}

关于我在这里做错了什么有什么建议吗?

【问题讨论】:

    标签: javascript rest sharepoint sharepoint-online


    【解决方案1】:

    您需要进行如下更改:

    1) 修改元数据如下:

    "__metadata":{"type":"SP.Publishing.PublishingSiteCreationRequest"},
    

    2) 您需要将parameters 替换为request

    3) 修改端点以创建通信站点如下:

    url: "https://companyname.sharepoint.com/_api/sitepages/publishingsite/create",
    

    3) 确保您从根站点(其 url 类似于 https://companyname.sharepoint.com/sitepages/RunSomeJS.aspx)运行代码,并且您是该根站点的网站集管理员。

    你的最终代码如下:

    function DoRestCall(){      
        var body={'request':
        {
            "__metadata":{"type":"SP.Publishing.PublishingSiteCreationRequest"},
            "AllowFileSharingForGuestUsers":false,
            "Classification":"MyTest Communication Site",
            "Description":"Here is my communication site",
            "SiteDesignId":"6142d2a0-63a5-4ba0-aede-d9fefca2c767",
            "Title":"MyTest Communication Site",
            "Url":"https://companyname.sharepoint.com/sites/testSiteName",            
            "lcid":1033
            }
        };
        $.ajax({
            type: 'POST',
            url: "https://companyname.sharepoint.com/_api/sitepages/publishingsite/create",
            contentType: 'application/json',
            processData: false,
            headers:{
                "accept":"application/json;odata=verbose",
                "content-type":"application/json;odata=verbose",
                "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value
            },
            data: JSON.stringify(body),
            success: function () 
            {
                alert('CREATION REQUEST SUBMITTED');
            },
            error: function(data){
                alert('failure:' + data.statusText );
            }
        });
    }
    

    【讨论】:

    • 嘿@user3156,运气好吗?我在我的租户中尝试过,它在我的租户中有效
    • 是的,这对我有用!我还验证了它不必在租户的根网站集中运行 - 我能够在另一个网站集中运行它。另外,我被告知他们是此处描述的站点创建 API 的一个错误 docs.microsoft.com/en-us/sharepoint/dev/apis/… - 希望在不久的将来得到解决(现在该网址上有一个说明)
    猜你喜欢
    • 1970-01-01
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 2023-03-09
    相关资源
    最近更新 更多