Mutation create_item - how to format date column?

Hi, I am trying to create a new item and set the columns values from the beginning to avoid changing the values in a separate API call.

mutation {
  create_item(
    item_name: "Name",
    board_id: ID,
    group_id: "GROUP",
    
      column_values: "{\"date\": \"2019-01-20\" }" )
  {
    id
  }
}

This gives me this error:

  "error_code": "ColumnValueException",
  "status_code": 400,
  "error_message": "change_column_value invalid value",
  "error_data": {
    "column_value": "2019-01-20",
    "column_type": "DateColumn"

Any suggestions?

Hey Ahmed! The data for the date column should be in the format {"date" : "2019-01-20", "time" : "00:00:00"}. Try sending this instead:

"{ \"date\" : { \"date\" : \"2019-01-20\" } }

The first “date” is the column ID of the date column, and the second “date” tells the column to assign the cell with the date value of Jan 20. Let me know if that does the trick.

Thanks so much @dipro.

This works on GraphiQL but I am facing another issue when I moved the code to a Node JS project. Could you please help?

GrahiQL:

mutation {
  create_item(
    item_name: "TEST API 3", 
    board_id: ID, 
    group_id: "new_group", 
    column_values: "{\"people2\": null, \"text1\": \"Test Lead\", \"client4\": \"Test Client\", \"channel5\":\"Test channel\", \"status8\":null, \"text\": \"Test req by\", \"date\": { \"date\" : \"2019-01-20\" } }")
   {
    id
  }
}

Node JS:

const body = {
			query: `
			mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
				create_item (
					board_id: $boardId,
					group_id: $groupId,
					item_name: $itemName,
					column_values: $columnValues
				) {
					id
				}
			}
			`,
			variables: {
				boardId: ID,
				groupId: "new_group",
				itemName: "TEST - API New Request",
				columnsValues: JSON.stringify({
					people2: null,
					text1: "Test Lead",
					client4: "Test Client",
					channel5: "Test channel",
					status8: null,
					text: "Test req by",
					date: { date: "2019-01-20" }
				})
			}
		};

		axios
			.post(`https://api.monday.com/v2`, body, {
				headers: {
					Authorization: "AUTH"
				}
			})
			.catch(err => {
				console.error("** error **", err.data);
			})
			.then(res => {
				console.log("** success **", res.data);
			});

Output:

** success ** {
  errors: [
    {
      message: 'Variable columnValues of type JSON! was provided invalid value',
      locations: [Array],
      value: null,
      problems: [Array]
    }
  ],
  account_id: ID
}

Hi @dipro, have you got a chance to see my above issue? I am unable to understand what is wrong. Please help me.

1 Like

Try this instead for your column_values
The columns you are trying to make null are expecting a json object type but being given null. To make the field null you need to give a json object with a null key pair i.e. {null:null}

Thanks @Alex.M. Unfortunately it shows this error:

{

* errors: [
  * {
    * message: "Variable columnValues of type JSON! was provided invalid value",

    * locations: [
      * {
        * line: 2,

        * column: 69}],

    * value: null,

    * problems: [
      * {
        * path: [ ],

        * explanation: "Expected value to not be null"}]}],

* account_id: 1580874

}

For this query:

{
			query: `
			mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
				create_item (
					board_id: $boardId,
					group_id: $groupId,
					item_name: $itemName,
					column_values: $columnValues
				) {
					id
				}
			}
			`,
			variables: {
				boardId: 393850461,
				groupId: "new_group",
				itemName: "TEST - API New Request",
				columnsValues: JSON.stringify({ people2: { null: null }, text1: "Test Lead", client4: "Test Client", channel5: "Test channel", status8: { null: null }, text: "Test req by", date: { date: "2019-01-20" } })
			}
		};

Hey Ahmed,

Instead of sending {null:null} for the value of people2, just omit it. If you don’t include a column in the values you send it will be set as empty :slight_smile:

Let me know if that helps!

Hi @dipro, for the sake of trial, I only sent the values of a single text field, and also I received the same error.

	query: `
			mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
				create_item (
					board_id: $boardId,
					group_id: $groupId,
					item_name: $itemName,
					column_values: $columnValues
				) {
					id
				}
			}
			`,
			variables: {
				boardId: ID,
				groupId: "new_group",
				itemName: "TEST - API New Request",
				columnsValues: JSON.stringify({ text1: "Test Lead" })
			}

Output

    {
      message: 'Variable columnValues of type JSON! was provided invalid value',
      locations: [Array],
      value: null,
      problems: [Array]
    }
  ],

Looks like you have a variable mismatch. In your create_item mutation you have the variable $columnValues but in the variables it is defined as columnsValues.

@Alex.M You are totally correct. Thank you so much.
I wish someone could fix the typo in this code snippet: Node.js mutation example using Axios - #5 by jtran

1 Like

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