首页 > 解决方案 > 使用 microsoft graph 在 sharepoint 站点上创建页面

问题描述

目前我正在尝试在一个新创建的站点上创建一个带有一些虚拟数据的页面。根据https://docs.microsoft.com/en-us/graph/api/sitepage-create?view=graph-rest-beta应该可以使用这样的 json 创建页面:

POST https://graph.microsoft.com/beta/sites/tenant.sharepoint.com%2Cee2667f8-2bae-460e-944b-613773baaa03%2C8c0054a6-6e0e-49cd-be6d-4c4c0aaf644e/pages HTTP/1.1
Authorization: Bearer <token>
User-Agent: Java-Client
Accept-Encoding: gzip,deflate
Accept: application/json, text/json
Content-Type: application/json; charset=UTF-8
Host: graph.microsoft.com
Connection: keep-alive
Content-Length: 167

{"name":"Testpage21.aspx","publishingState":{"level":"published","versionId":"0.1"},"title":"Testpage21","webParts":[{"type":"rte","innerHTML":"<h1>Hello!</h1>"}]}

因为你看不到任何花哨的东西。不幸的是,在发出此请求时,我收到以下错误响应:

HTTP/1.1 500 Internal Server Error
Cache-Control: private
Content-Type: application/json
request-id: 1dba7669-1318-488a-a416-63fddbdfcda1
client-request-id: 1dba7669-1318-488a-a416-63fddbdfcda1
Duration: 833.8091
Strict-Transport-Security: max-age=31536000
Date: Fri, 04 Jan 2019 15:13:15 GMT
Content-Length: 236

{
  "error": {
    "code": "generalException",
    "message": "General exception while processing",
    "innerError": {
      "request-id": "1dba7669-1318-488a-a416-63fddbdfcda1",
      "date": "2019-01-04T15:13:16"
    }
  }
}

当我从初始请求中删除 webparts 属性时,POST 成功,我得到如下响应:

{"@odata.context":"https://graph.microsoft.com/beta/$metadata#sites('tenant.com%2Cee2667f8-2bae-460e-944b-613773baaa03%2C8c0054a6-6e0e-49cd-be6d-4c4c0aaf644e')/pages/$entity","eTag":"\"{DA2C2C0C-2222-4F11-917E-7B4BBFE8AC99},3\"","id":"da2c2c0c-2222-4f11-917e-7b4bbfe8ac99","lastModifiedDateTime":"2019-01-04T15:08:12Z","name":"Testpagina2.aspx","webUrl":"SitePages/Testpagina2.aspx","title":"Testpagina2","pageLayout":"Article","parentReference":{"siteId":"ee2667f8-2bae-460e-944b-613773baaa03"},"contentType":{"id":"0x0101009D1CB255DA76424F860D91F20E6C411800A19AB965C0D2B54C82DFCC03DBE6A732","name":"Sitepagina"},"publishingState":{"level":"checkout","versionId":"0.1"}}

但是,我当然想在发布之前向页面添加至少一些内容( html )。

有人可以告诉我使用 Graph 创建页面的功能是否还没有完全发挥作用吗?或者我错过了什么。

ps 有哪些类型的 webparts 可用?

标签: sharepointmicrosoft-graph-api

解决方案


不幸的是,我们的文档中有一个错误(指定为修复),“innerHTML”属性应该像其他 Web 部件的属性一样包装在“数据”属性中。以下是您的有效载荷应如下所示:

{
  "name":"Testpage21.aspx",
  "publishingState":{"level":"published","versionId":"0.1"},
  "title":"Testpage21",
  "webParts": [{
      "type":"rte",
      "data": {
        "innerHTML":"<h1>Hello!</h1>"
      }
  }]
}

就可用的 Web 部件而言,任何部件都应该可以工作,但我们还没有记录与当前 Beta 版本相关的数据结构。这通常使 API 对于您自己的自定义 Web 部件最有用,您已经知道数据块中需要具有哪些属性。


推荐阅读