Formatting help on MondayClient Query?

Hi, I’m new to developing on and I need some help formatting a graphQL query using the 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();

		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) { 
		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);
	} catch (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.

await mondayClient.api(query, { variables: vars }) is the correct usage for making the request. The variables are sent as the variables key of the options object (the second argument of the .api method is the options object, not the variables.)

This fixed it! Thank you so much!

1 Like

Thank you @codyfrisch for the help here!