无法在OneNote页面中进行两项更改

时间:2018-10-04 04:37:37

标签: microsoft-graph onenote onenote-api

我需要通过MS Graph API在用户页面中完成待办事项。如果待办事项在列表中,则在待办事项的替换操作之后,该列表将损坏。幸运的是,我发现了一个可以完成待办事项的骇客,但又没有打破清单:Working with OneNote Page Content via the Graph API

  1. 在目标待办事项之前插入完整的副本
  2. 用空块替换目标待办事项

如果我在一个请求中发送这2个操作-API返回500。

可以修复它吗?


有关页面和请求的详细信息:

enter image description here

页面布局(GET /me/onenote/pages/{{pageId}}/content?includeIDs=true

<html lang="en-US">
    <head>
        <title>Nested list</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="created" content="2018-10-04T09:46:00.0000000" />
    </head>
    <body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
        <div id="div:{b883c993-0084-480b-9f15-3b0407435f29}{144}" style="position:absolute;left:96px;top:139px;width:624px">
            <p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{146}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Super task</p>
            <p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{153}" style="margin-top:0pt;margin-bottom:0pt">Point 1</p>
            <p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{155}" style="margin-top:0pt;margin-bottom:0pt">Point 2</p>
            <p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{149}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Mega task</p>
            <p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{151}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Mega subtask</p>
        </div>
    </body>
</html>

更新请求(PATCH /me/onenote/pages/{{pageId}}/content):

[
  {
    "action": "insert",
    "position": "before",
    "target": "p:{b883c993-0084-480b-9f15-3b0407435f29}{146}",
    "content": "<p data-tag=\"to-do:completed\" style=\"margin-top:0pt;margin-bottom:0pt\">Super task</p>"
  }, {
    "action": "replace",
    "target": "p:{b883c993-0084-480b-9f15-3b0407435f29}{146}",
    "content": "<span></span>"
  }
]

API响应:

{
    "error": {
        "code": "19999",
        "message": "Something failed, the API cannot share any more information at the time of the request.",
        "innerError": {
            "request-id": "d352cd80-b40d-4d55-b984-2bb5cae07f2b",
            "date": "2018-10-04T04:24:25"
        }
    }
}

1 个答案:

答案 0 :(得分:0)

  

是否可以修复它?

是的。通过使用batch request

一个为您解决的方法,我仍在努力格式化主体数据:

   {
  "requests": [
    {
      "id": "1",
      "url": "/me/onenote/pages/{page-id}/content",
      "method": "PATCH",
      "body": {
        "value": [
          {
            "action": "insert",
            "position": "before",
            "target": "p:{04b55584-a5f7-4ac2-b34d-474ebe346ce8}{69}",
            "content": "<p data-tag=\"to-do:completed\" style=\"margin-top:0pt;margin-bottom:0pt\">Super task</p>"
          }
        ]
      },
      "headers": {
        "Content-Type": "application/json"
      }
    },
    {
      "id": "2",
      "url": "/me/onenote/pages/{page-id}/content",
      "method": "PATCH",
      "body": {
        "value": [
          {
            "action": "replace",
            "target": "p:{04b55584-a5f7-4ac2-b34d-474ebe346ce8}{69}",
            "content": "<span></span>"
          }
        ]
      },
      "headers": {
        "Content-Type": "application/json"
      }
    }
  ]
}