Skip to main content

I’m trying to understand basic item creation. I can create a new item successfully with a name but when I try to add additional column content I get errors.


  monday.api(
`mutation {
create_item (
board_id: ${myBoardId},
group_id: "new_group",
item_name: "new item creation",
column_values: {
person: 20602378,
}
)
{
id
}
}`
)

It works if I remove the column-values object.

Hey @ShawnBaden 👋


Thank you for sharing this and I’m sorry that creating items with People column values has been giving you some trouble! I would recommend trying to send the values as a string, or as part of your variables. This seems to have worked well for me in the Playground:


mutation {
create_item (board_id:1232810882, item_name:"test", column_values: "{\\"person\\":\\"9603417\\"}") {
id
}
}

Also, you might want to make sure that the user you are trying to be to the item is part of the board - if they are not part of the Shareable or PRivate board you are creating an item on, the user will not be assigned to the item.


I hope this helps!


-Alex


I’m getting an error: Line 106:28: Unnecessary escape character: "


I’m using the monday.api call from the react bootstrap so my code looks like this:


monday.api(
`mutation {
create_item (
board_id:${myBoardId},
group_id: "new_group",
item_name: "test item"
column_values: "{\\"person\\":\\"9603417\\"}"
)
{
id
}
}`
)

If I remove the \\ I get undefined in the response.


I’ve also tried passing a string as a variable like this:


let columnValues = JSON.stringify({
person: 20602378,
text0: "Requestor name",
text9: "Notes",
dropdown: d0],
})

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)
};
});

Also, I’m using my own id for person as a test so I know it’s good.


@ShawnBaden


Thank you for circling back with me here! Would you be able to try wrapping your column IDs in quotes, so that the column values become the following:


let columnValues = JSON.stringify({
"person": 20602378,
"text0": "Requestor name",
"text9": "Notes",
"dropdown": [0],
})

I’m also not quite sure if you need curly brackets around the values, like {columnValues} or {boardId}, unless you are adding the variables to the call as GraphQL variables.


Would you be able to try out the 2 points above and let us know if that helped at all?


-Alex


@AlexSavchuk


I tried adding quotes and the create_item didn’t get logged and no item was created.


let columnValues = JSON.stringify({
"person": 20602378,
"text0": "Requestor name",
"text9": "Notes",
"dropdown": :0],
})

I removed the curly braces but then had to convert the colons to = and had to remove the Quotes from the column ids which makes them variables that haven’t been declared - not sure this one is going in the right direction.


let columnValues = JSON.stringify(
person= 20602378,
text0= "Requestor name",
text9= "Notes",
dropdown= w0],
)

For all future readers: this issue has since been resolved!


There were a myriad of issues at play, including the proper JSON formatting for a Person vs. a People column, as well as some other formatting issues for the columnValues values.


Make sure to check our documentation for changing column values using JSON for the proper formatting: https://monday.com/developers/v2#column-values-section!


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);
});

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.