简体   繁体   English

如何阻止 DevOps REST API 将传入的 JSON 有效负载包装在双引号中?

[英]How do I stop the DevOps REST API from wrapping an incoming JSON payload in double quotes?

I am attempting to use the ADO REST API to attach files to work items.我正在尝试使用 ADO REST API 将文件附加到工作项。 The problem seems to be that the incoming string is getting wrapped in double quotes at some point in the process.问题似乎是传入的字符串在过程中的某个时刻被双引号括起来。 This can be seen in any attached.txt files (which open fine), and renders.png and.jpg files unable to be opened.这可以在任何附加的.txt 文件(可以正常打开)中看到,并且 renders.png 和 .jpg 文件无法打开。 The content I'm trying to attach is attachment "content bytes" pulled from Outlook via a connector in Oracle Integration Cloud, which I base 64 decode in OIC before sending to ADO.我要附加的内容是通过 Oracle 集成云中的连接器从 Outlook 中提取的附件“内容字节”,在发送到 ADO 之前,我在 OIC 中进行了 64 位解码。

This is the call I use to create the attachment in ADO (media type is application/json-patch+json):这是我用来在 ADO 中创建附件的调用(媒体类型是 application/json-patch+json):

https://dev.azure.com/{org}/{project}/_apis/wit/attachments?api-version=6.0

"[]"

This is the response from that that I use to make the next call (media type is JSON):这是我用来进行下一次调用的响应(媒体类型为 JSON):

{
  "id" : "",
  "url" : ""
}

This is the next call to then associate the attachment with a specific work item (media type is application/json-patch+json):这是将附件与特定工作项关联的下一个调用(媒体类型为 application/json-patch+json):

https://dev.azure.com/{org}/{project}/_apis/wit/workitems/{id}?api-version=6.0

{
  "op" : "add",
  "path" : "/relations/-",
  "value" : {
    "rel" : "AttachedFile",
    "url" : ""
  }
} 

Is there an html header or something I can use to prevent this from happening?是否有 html header 或我可以用来防止这种情况发生的东西?

Thanks!谢谢!

Soooo, it turns out Microsoft's docs are somewhat misleading and suggest that ADO is expecting a JSON payload for attachment creation when it is actually expecting just binary content.太棒了,事实证明微软的文档有些误导,并建议 ADO 期望 JSON 有效负载用于创建附件,而实际上它只期望二进制内容。 Once I found that out I used the function "decodeBase64ToReference" in OIC on the "contentBytes" from outlook.一旦我发现我在 outlook 的“contentBytes”上使用了 OIC 中的 function“decodeBase64ToReference”。 I then reconfigured my OIC connector to send a binary payload and mapped everything accordingly.然后我重新配置了我的 OIC 连接器以发送二进制有效负载并相应地映射所有内容。 Worked like a charm.像魅力一样工作。

https://i.stack.imgur.com/92tPs.png https://i.stack.imgur.com/92tPs.png

https://i.stack.imgur.com/WSKnt.png https://i.stack.imgur.com/WSKnt.png

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM