Hi, I’m new to developing on Monday.com and I need some help formatting a graphQL query using the monday.com client. I’ve tried just about everything I can think of but continue to run into errors!
Here’s my code:
try {
const mondayClient = initMondayClient();
mondayClient.setToken('MyAccessToken');
mondayClient.setApiVersion('2024-04');
const query = `mutation create_item($board_id: ID!, $my_item_name: String!, $columnVals: JSON!) {
create_item(board_id: $board_id, item_name: $my_item_name, column_values: $columnVals) {
id
}
}`;
const vars = {
"my_item_name" : "Newest Purchase",
"board_id": '11111111111',
"columnVals" : JSON.stringify({
"status45" : {"label" : "Under Review"},
"status4" : {"label" : "J199"}, //Project #
"dropdown" : {"dropdown" : "MCMaster"}, //Vendors
})
};
const response = await mondayClient.api(query, vars);
console.log(response);
} catch (err) {
console.log(err);
}
The most common error I see is this:
“Variable $board_id of type ID! was provided invalid value”
“Variable $my_item_name of type String! was provided invalid value”
“Variable $columnVals of type JSON! was provided invalid value”
I’ve also tried formatting the variables like this:
const vars = {
"my_item_name" : "Newest Purchase",
"board_id": '1111111111',
"columnVals" : "{\\"status45\\" : \\"Under Review\\", \\"status4\\" : \\"J199\\"}"
};
same errors.
This code works great if I run it through a javascript fetch function rather than through the monday client. Which is why I know it’s just a formatting issue.
Obviously in my real code I use the correct token, and board_ID.
Please help! I’m not sure what I’m doing wrong.