reactjs - 如何在 Monday.com 中使用列值创建新的板项目?代码不工作
问题描述
我在 React 引导应用程序中使用 Monday.com API。
我可以使用项目名称成功创建一个新的板项目...
monday.api(
`mutation {
create_item (
board_id: ${myBoardId},
group_id: "new_group",
item_name: "new item creation",
)
{
id
}
}`
)
...但是当我尝试添加其他列值时,我收到 POST 500 错误。
monday.api(
`mutation {
create_item (
board_id: ${myBoardId},
group_id: "new_group",
item_name: "new item creation",
column_values: {
person: 00000000,
}
)
{
id
}
}`
)
我试过为列值传递一个字符串......
let columnValues = JSON.stringify({
person: 00000000,
text0: "Requestor name",
text9: "Notes",
dropdown: [0],
})
monday.api(
`mutation {
create_item (
board_id:${myBoardId},
group_id: "new_group",
item_name: "test item",
column_values: ${columnValues}
)
{
id
}
}`
).then(res => {
if(res.data){
console.log('new item info: ', res.data)
};
});
...但没有创建任何项目,我没有收到任何错误,也没有任何日志。
解决方案
问题可能出在您的 GraphQL 查询上。要在星期一创建项目,您需要提供column_values。不幸的是,在星期一的 API 文档中并没有明确说明应该如何完成。可以在Monday API 文档的使用 JSON 更改列值部分中找到如何将column_values 配置为create_item查询的答案
请尝试以下代码:
const board_id = "<board_id>"
const group_id = "<group_id>"
const person_id = "<person_id>"
const item_name = "<item name>"
let query = `mutation { create_item (board_id:${board_id},group_id: \"${group_id}\",item_name: \"${item_name}\",column_values: \"{\\\"person\\\":\\\"${person_id}\\\"}\"){id}}`
monday.api(query).then((res) => {
console.log(res);
})
在哪里,
- <board_id> - 你的董事会 ID
- <group_id> - 你的组 ID
- <item_name> - 您要创建的项目的名称
- <person_id> - 用户 ID
如果您使用console.log查询,您应该会看到如下内容:
mutation { create_item (board_id:1293656973,group_id: "group_1",item_name: "New Item",column_values: "{\"person\":\"14153685\"}"){id}}
请注意,在查询变量中,我使用的是String Interpolation。所以字符串应该以`符号开始和结束
您还可以随时转储您的 GraphQL 查询并使用Monday API Try-It own tool 在线测试它们
推荐阅读
- solr - Apache Solr - termfreq 函数中的单词计数错误
- parsing - RuntimeWarning:无法解码来自 CoreNLP 服务器的序列化输出。将返回不完整或空的对象
- python - 如何将 Pandas 数据框加载到 Surprise 数据集中?
- java - 在java地图集合中获取空指针异常。如何处理地图中的空指针异常
- c - C 将 char* 字符串转换为 int 数组
- python - 用相似代码绘制图形
- python - 如何将 torch.device('cuda' if torch.cuda.is_available() else 'cpu') 编写为完整的 if else 语句?
- javascript - HighCharts y 轴设置最小值最大值与渲染图轴上的输入字段
- python - 在 fillna() 函数中使用 shift() 的目的是什么?
- sql-server - 使用 ssis 从 SQL Server 表复制到 Oracle 11g