I'm using the Monday.com API in a React bootstrapped app.
I can create a new board item successfully with an item name...
monday.api(
`mutation {
create_item (
board_id: ${myBoardId},
group_id: "new_group",
item_name: "new item creation",
)
{
id
}
}`
)
...but when I try to add additional column values I get a POST 500 error.
monday.api(
`mutation {
create_item (
board_id: ${myBoardId},
group_id: "new_group",
item_name: "new item creation",
column_values: {
person: 00000000,
}
)
{
id
}
}`
)
I've tried passing a string in for the column values...
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 no item is created, I get no errors and nothing logs.
Here was the solution:
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);
});