我在一个反应引导应用程序中使用了Monday.com API。
我可以用项目名成功地创建一个新的董事会项目.
monday.api(
`mutation {
create_item (
board_id: ${myBoardId},
group_id: "new_group",
item_name: "new item creation",
)
{
id
}
}`
)...but当我试图添加额外的列值时,我会得到一个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)
};
});...but没有创建任何项,我没有错误,也没有日志。
发布于 2021-06-01 17:17:25
解决办法如下:
const variables = ({
boardId : 00000000,
groupId: "new_group",
itemName : "New Item",
columnValues: JSON.stringify({
people78: {
personsAndTeams: [
{
id: 00000000,
kind: "person"
}
]
},
text0: "Yosemite Sam",
dropdown: {
labels: [
"TAM"
]
},
})
});
const query = `mutation create_item ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
create_item (
board_id: $boardId,
group_id: $groupId,
item_name: $itemName,
column_values: $columnValues
)
{
id
}
}`;
monday.api(query, {variables}).then((res) => {
console.log('new item info: ', res);
});发布于 2021-05-14 10:01:30
问题可能在于您的GraphQL查询。要在星期一创建一个项目,您需要提供column_values.不幸的是,在周一的API文档中,它没有明确规定应该如何完成。如何将column_values提供给create_item查询的答案可以在使用星期一API文档的JSON部分的更改列值中找到
请尝试以下代码:
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);
})哪里,
如果您使用console.log查询,您应该会看到如下内容:
mutation { create_item (board_id:1293656973,group_id: "group_1",item_name: "New Item",column_values: "{\"person\":\"14153685\"}"){id}}请注意,在查询变量中,我正在使用串内插。所以字符串应该以‘符号开头和结尾
您还可以始终转储GraphQL查询并使用周一API自己尝试-It工具在线测试它们。
https://stackoverflow.com/questions/67439159
复制相似问题