通过 Monday.com API 使用 ColdFusion 添加文件时出现问题

发布于 2025-01-17 05:36:23 字数 2210 浏览 1 评论 0原文

我一直在使用 Monday API,并在使其准备好在我们的系统和我们使用的其他一些工具中可用方面取得了很大进展,但是,当涉及到它时,我遇到了一些障碍添加文件。我已经能够做其他所有事情,从添加项目、更新、专栏、看板到阅读我需要的内容,但添加文件最终让我崩溃。我的代码基于 将文件上传到 monday.com,困难的方式。作者使用的是 NodeJS,所以我尽力对其进行转换。 我的代码如下:

<cfset dataQuery = 'mutation ($file:File!) {add_file_to_column (item_id: 123456789, column_ID: file, file: $file){id}}'>
<cfset boundary = "xxxxxxxxxx">
<cfset upfile = "image1.png">
<cfset base64Sample = SAMPLE_BASE64_STRING>
<cfset data = "">

<!--- Construct Query --->
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">
<cfset data &= 'Content-Disposition: form-data; name="query"#chr(13)##chr(10)##chr(13)##chr(10)#'>
<cfset data &= dataQuery & '#chr(13)##chr(10)#'>
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">

<!--- Construct File --->
<cfset data &= 'Content-Disposition: form-data; name="variables[file]"; filename="' & upfile & '";#chr(13)##chr(10)#'>
<cfset data &= "Content-Type:application/octet-stream;#chr(13)##chr(10)##chr(13)##chr(10)#">
<cfset data &= ToString(ToBinary(base64Sample))>
<cfset data &= "#chr(13)##chr(10)#--" & boundary & "--#chr(13)##chr(10)#">

<cfdump var="#data#">
<cfhttp method="post" url="https://api.monday.com/v2" result="result">
    <cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=#boundary#">
    <cfhttpparam type="Header" name="Authorization"  value="#mondayLogin.Token#">
    <cfhttpparam type="body" value="#data#">
</cfhttp>

当我试图让它工作时,格式已经发生了一些变化,但无论我做什么,它总是给我相同的错误消息:“不存在查询字符串”。

我希望这里对多部分边界和 Monday API 有更多了解的人可以提供帮助。

编辑:我将 \r\n 更改为 chr(13)chr(10) ,但仍然遇到相同的错误。

编辑 2:经过更多的重构后,我似乎已经克服了第一个错误,现在我遇到了 2 个与 GraphQL 相关的新错误,我认为。

  • 字段“add_file_to_column”缺少必需参数:column_id
  • 字段“add_file_to_column”不接受参数“column_ID” 我确信我仍然在某个地方格式化错误,但我还不知道那在哪里。

编辑3:原来我的列名是错误的。 “ID”不应大写,而应为“column_id”。我现在收到另一个新错误:内部服务器错误 (500)

I’ve been playing with the Monday API and have made a lot of progress towards getting it ready to be available in our system and a couple of other tools we use, however, I’ve hit a bit of a snag when it comes to adding files. I’ve been able to do everything else from adding items, updates, columns, boards and reading what I’ve needed, but adding files is what has finally broken me. I’m basing my code off of Uploading a file to monday.com, the hard way. The author is using NodeJS so I’ve tried to convert it as best I can.
My code below:

<cfset dataQuery = 'mutation ($file:File!) {add_file_to_column (item_id: 123456789, column_ID: file, file: $file){id}}'>
<cfset boundary = "xxxxxxxxxx">
<cfset upfile = "image1.png">
<cfset base64Sample = SAMPLE_BASE64_STRING>
<cfset data = "">

<!--- Construct Query --->
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">
<cfset data &= 'Content-Disposition: form-data; name="query"#chr(13)##chr(10)##chr(13)##chr(10)#'>
<cfset data &= dataQuery & '#chr(13)##chr(10)#'>
<cfset data &= "--" & boundary & "#chr(13)##chr(10)#">

<!--- Construct File --->
<cfset data &= 'Content-Disposition: form-data; name="variables[file]"; filename="' & upfile & '";#chr(13)##chr(10)#'>
<cfset data &= "Content-Type:application/octet-stream;#chr(13)##chr(10)##chr(13)##chr(10)#">
<cfset data &= ToString(ToBinary(base64Sample))>
<cfset data &= "#chr(13)##chr(10)#--" & boundary & "--#chr(13)##chr(10)#">

<cfdump var="#data#">
<cfhttp method="post" url="https://api.monday.com/v2" result="result">
    <cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=#boundary#">
    <cfhttpparam type="Header" name="Authorization"  value="#mondayLogin.Token#">
    <cfhttpparam type="body" value="#data#">
</cfhttp>

The formatting has gotten shifted a little bit as I tried to get it working but no matter what I do, it always gives me the same error message: “No query string was present”.

I’m hoping someone here who has more knowledge about doing multi-part boundaries and the Monday API can help.

Edit: I changed the \r\n to the chr(13)chr(10) and am still getting the same error.

Edit 2: After a little more refactoring on it I seem to have gotten past the first error and now I've hit 2 new one that are related to GraphQL I think.

  • Field 'add_file_to_column' is missing required arguments: column_id
  • Field 'add_file_to_column' doesn't accept argument 'column_ID'
    I'm sure I'm still formatting it wrong somewhere but I don't see where that is yet.

Edit 3: Turns out my column name was wrong. The 'ID' shouldn't have been in caps but should be 'column_id'. I'm now getting another new error of: Internal server error (500)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍白女子 2025-01-24 05:36:23

所以我遇到了很多问题,有很多不同的错误消息。基本上我有 3 个问题:

  1. 将我的 \r\n 替换为 chr(13)chr(10) 的正确 ColdFusion 值
  2. 根据文档
  3. ColdFusion 在编译时以不同的方式对待单引号 (') 和双引号 (")。一旦我转义了双引号并删除了单引号,我就能够让它工作了。下面是我的工作演示。
<cfset dataQuery = "mutation ($file:File!) {add_file_to_column (item_id: 123456789, column_id: files, file: $file){id}}">
<cfset boundary = "xxxxxxxxxx">
<cfset upfile = "image1.png">
<cfset base64Sample = "SAMPLE_BASE64_IMAGE">
<cfset data = "">
<cfset cflf = "#chr(13)##chr(10)#">

<!--- Construct Query --->
<cfset data &= "--" & boundary & "#cflf#">
<cfset data &= 'Content-Disposition: form-data; name="query"#cflf##cflf#'>
<cfset data &= dataQuery & '#cflf#'>
<cfset data &= "--" & boundary & "#cflf#">

<!--- Construct File --->
<cfset data &= "Content-Disposition: form-data; name=""variables[file]""; filename=""#upfile#"";#cflf#">
<cfset data &= "Content-Type:application/octet-stream;#cflf##cflf#">
<cfset data &= ToString(ToBinary(base64Sample))>
<cfset data &= "#cflf#" &"--" & boundary & "--">

<cfdump var="#data#">
<cfhttp method="post" url="https://api.monday.com/v2/file" result="result">
    <cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=#boundary#">
    <cfhttpparam type="Header" name="Authorization"  value="API_KEY_HERE">
    <cfhttpparam type="body" value="#data#">
</cfhttp>

<cfset returnStruct = DeserializeJSON(result.filecontent)>

<cfdump var="#returnStruct#">

So I ran into MANY issues on this with a lot of different error messages. Basically I had 3 issues:

  1. Replace my \r\n with the correct ColdFusion values of chr(13)chr(10)
  2. The formatting of the query was incorrect according to the documentation
  3. ColdFusion treats single quotes(') and double quotes(") differently when compiling them. Once I escaped the double quotes and removed the single quotes I was able to get it working. Below is my working demo.
<cfset dataQuery = "mutation ($file:File!) {add_file_to_column (item_id: 123456789, column_id: files, file: $file){id}}">
<cfset boundary = "xxxxxxxxxx">
<cfset upfile = "image1.png">
<cfset base64Sample = "SAMPLE_BASE64_IMAGE">
<cfset data = "">
<cfset cflf = "#chr(13)##chr(10)#">

<!--- Construct Query --->
<cfset data &= "--" & boundary & "#cflf#">
<cfset data &= 'Content-Disposition: form-data; name="query"#cflf##cflf#'>
<cfset data &= dataQuery & '#cflf#'>
<cfset data &= "--" & boundary & "#cflf#">

<!--- Construct File --->
<cfset data &= "Content-Disposition: form-data; name=""variables[file]""; filename=""#upfile#"";#cflf#">
<cfset data &= "Content-Type:application/octet-stream;#cflf##cflf#">
<cfset data &= ToString(ToBinary(base64Sample))>
<cfset data &= "#cflf#" &"--" & boundary & "--">

<cfdump var="#data#">
<cfhttp method="post" url="https://api.monday.com/v2/file" result="result">
    <cfhttpparam type="Header" name="Content-Type" value="multipart/form-data; boundary=#boundary#">
    <cfhttpparam type="Header" name="Authorization"  value="API_KEY_HERE">
    <cfhttpparam type="body" value="#data#">
</cfhttp>

<cfset returnStruct = DeserializeJSON(result.filecontent)>

<cfdump var="#returnStruct#">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文