使用Microsoft Graph在Sharepoint网站上创建页面 [英] Creating pages on sharepoint site with microsoft graph

查看:103
本文介绍了使用Microsoft Graph在Sharepoint网站上创建页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently I'm trying to create a page on a newly created site with some dummy data. According to https://docs.microsoft.com/en-us/graph/api/sitepage-create?view=graph-rest-beta it should be possible to create a page using json like this:

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>"}]}

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

as you can see nothing fancy. Unfortunatly when issueing this request I receive the following error response:

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成功后,我将收到如下响应:

When I remove the webparts property from my initial requests the POST succeeds I get response like this:

{"@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).

But ofcourse I would like to add at least some content ( html ) to the page before I publish it.

有人可以告诉我使用Graph创建页面是否还不能完全正常工作吗?还是我想念一些东西.

Could someone tell me if the creation of pages using Graph is not yet fully functional? Or that I'm missing something.

p.s.可以使用哪种Webpart?

p.s. what kind of webparts are available?

推荐答案

不幸的是,我们的文档中有一个错误(已分配为固定错误),"innerHTML"属性应包装在"data"属性中,例如其他Web部件.这是您的有效载荷应如下所示:

Unfortunately we have a bug in our docs (assigned to be fixed), the "innerHTML" property should be wrapped in a "data" property like the properties of other web parts. Here's what your payload should look like:

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

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

In terms of what web parts are available any part should work but we have not documented the data structures associated with them for the current Beta release. That generally makes the API most useful with your own custom web parts where you already know what properties you need to have in the data block.

这篇关于使用Microsoft Graph在Sharepoint网站上创建页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆