本文介绍了Onenote API (REST) - PATCH 附加 -“必须包含一个‘命令’";已提供命令时出错 (?!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我很确定 PATCH 查询没有问题,我之前使用 'Content-type':'application/json' 和构造的 json 文件工作:

[{'目标':'|TARGET_ID|','动作':'追加','内容':'|HTML|'}]

为此,提供的标头(身份验证承载正确,将被省略)

'Content-type':'multipart/form-data;边界=截面边界'

(注意:Boundary=sectionboundary 在同一行)

尝试将以下主体作为 PATCH 传递给
https://www.onenote.com/api/v1.0/pages/|GUID|/content返回一个"code":"20124","message":"多部分 PATCH 请求必须包含一个包含 PATCH 操作 JSON 结构的命令"部分.":

--sectionboundary内容配置:表单数据;名称=命令"内容类型:应用程序/json[{'目标':'|TARGET_ID|','动作':'追加','内容':'|HTML|'}]--sectionboundary内容配置:表单数据;名称=图像部分名称"内容类型:图像/png|BINARY_IMAGE_DATA|--截面边界--

如您所见,已经有一个命令部分.使用 smallcaps 'commands' 没有帮助,根据 OneNote Dev Center 文档,正确的语法应该是Commands".

附注:|TARGET_ID||HTML||用户名|和 |BINARY_DATA|在运行时替换为正确的内容.由于隐私限制,事实上您可能使用与我不同的模式,以及多长时间 |BINARY_IMAGE_DATA|实际上是,除非需要解决问题,否则我不会显示实际输入.

想知道我是否遗漏了什么 - 提前致谢.

PPS:是的,我意识到我在 |HTML| 中省略了 img 标签某处.它不应该与代码 20124 有任何关系,如果我弄错了,应该完全返回另一件事.

解决方案

根据对您共享的请求信息的调查,我可以确认作为您提供的相关性的一部分引用的 PATCH 请求与您发布的标头信息不匹配.相关的 PATCH 请求显示为一个多部分请求,其中只有一个部分具有媒体类型TEXT/HTML"而不是Application/JSON".您能检查并确认您的请求内容吗?让我们继续在电子邮件中讨论这个问题.如果您在调用 API 时仍然遇到问题,请通过 machandw@microsoft.com 写信给我

问候,马诺伊

Note: I'm pretty sure nothing's wrong with the PATCH query, I had it working before with 'Content-type':'application/json' and a constructed json file:

[
  {
  'target':'|TARGET_ID|',
  'action':'append',
  'content':'|HTML|'
  }
]

For the purposes of this, the header supplied (authentication bearer is correct and will be omitted)

'Content-type':'multipart/form-data; Boundary=sectionboundary'

(note: Boundary=sectionboundary is in the same line)

Attempting to pass the following body as a PATCH to
https://www.onenote.com/api/v1.0/pages/|GUID|/content returns a "code":"20124","message":"A multi-part PATCH request must include a 'commands' part containing the PATCH action JSON structure." :

--sectionboundary
Content-Disposition: form-data; name="Commands"
Content-Type: application/json
[
  {
  'target':'|TARGET_ID|',
  'action':'append',
  'content':'|HTML|'
  }
]

--sectionboundary
Content-Disposition: form-data; name="image-part-name"
Content-Type: image/png

|BINARY_IMAGE_DATA|

--sectionboundary--

As you can see, there's a Commands section already. Using smallcaps 'commands' doesn't help, and the correct syntax should be "Commands" as per the OneNote Dev Center documentation.

PS: |TARGET_ID| |HTML| |GUID| and |BINARY_DATA| are replaced with the correct content at runtime. Due to privacy constraints, the fact that you may use a different schema than I do, and how long |BINARY_IMAGE_DATA| actually is, I will not show the actual input unless required to solve the problem.

Would like to know if I missed anything - thanks in advance.

PPS: Yes, I realize i've omitted the img tag inside |HTML| somewhere. It shouldn't have anything to do with code 20124, and if I got it wrong should return another thing entirely.

解决方案

Based on investigating the request information you shared, I can confirm that the PATCH request referenced as part of the correlation you provided does not match your posted header information.The correlated PATCH request shows up as a multi-part request with only a single part that has Media Type "TEXT/HTML" and not "Application/JSON". Can you please check and confirm your request content ?Let us continue to discuss this on email. If you still face issues calling the API, please write to me at machandw@microsoft.com

Regards,Manoj

这篇关于Onenote API (REST) - PATCH 附加 -“必须包含一个‘命令’";已提供命令时出错 (?!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 15:35
查看更多