Clarification required for GQL update multiple columns for date values

Hi,

This query below keeps failing despite numerous variations of date formats.
I am running this in the app playground.
Would appreciate some advice to understand what the right format is.

mutation SetVolunteerInRequesterItem {
  change_multiple_column_values(
    item_id: 1317064012
    board_id: 1317064001
    column_values: "{\"date42\": \"{\\\"date\\\": \\\"2023-11-30\\\", \\\"time\\\": \\\"08:00:00\\\"}\"}"
  ) {
    id
  }
  move_item_to_group(group_id: "new_group73364", item_id: 1317064012) {
    id
  }
}

throws:

{
  "error_code": "ColumnValueException",
  "status_code": 200,
  "error_message": "invalid value, please check our API documentation for the correct data structure for this column. https://developer.monday.com/api-reference/docs/change-column-values",
  "error_data": {
    "column_value": "{\"date\"=>\"{\\\"date\\\":\\\"Tue,\", \"time\"=>\"28\"}",
    "column_type": "DateColumn"
  }
}

Hi @darkmift,

Welcome to the community :wave:

You can follow the format used in this example and the mutation will run! I will also paste the same query I tested it with (but replaced with my own IDs) below :slight_smile:

mutation SetVolunteerInRequesterItem {
  change_multiple_column_values(
    item_id: 1317064012
    board_id: 1317064001
    column_values: "{\"date42\": {\"date\": \"2023-11-30\", \"time\": \"08:00:00\"}}"
  ) {
    id
  }
  move_item_to_group(group_id: "new_group73364", item_id: 1317064012) {
    id
  }
}

Let us know if you have any other questions!

Best,
Rachel

1 Like

Hi Rachel,
Tyvm for your prompt assistance!

Im pasting here for any future visitors:

mutation SetRequesterMultipleValues {
  change_multiple_column_values(
    item_id: 1317064012
    board_id: 1317064001
    column_values: "{\"connect_boards5\":{\"linkedPulseIds\":[{\"linkedPulseId\":1316953659}]},\"date42\" : {\"date\" : \"2023-11-30\", \"time\" : \"08:00:00\"}}"
  ) {
    id
  }
  move_item_to_group(group_id: "new_group73364", item_id: 1317064012) {
    id
  }
}
1 Like

A strong suggestion, is create the “column_value” as an object in your code, then serialize it to JSON and use the string in the query. This will avoid needing to worry about ensuring everything is escaped correctly.

I also suggest looking at GraphQL variables: https://graphql.org/learn/queries/#variables

The below example assumes you’re setting API-Version to 2023-10 (not shown in the code). The advantage of variables is you do not need to worry about string substitutions and ensuring everything is properly escaped. As you see I also am serializing values to JSON to meet the requirement that column_values be a JSON string (denoted by the $values: JSON! for the variable definition). API 2023-10 uses ID type rather than Int type, ID can be a string or integer. Note that right now the item ID in linkedPulseIds must be an integer but I’ve heard that is getting fixed soon since its a bug. One reason for using strings, is that is how the IDs are returned by the API.

const query = `mutation (
 $boardId: ID!,
 $itemId: ID!, 
 $values: JSON!,
 $groupId: ID!) 
 SetRequesterMultipleValues {
  change_multiple_column_values(
   item_id: $itemId,
   board_id: $boardId,
   column_values: $values) {
     id
   }

   move_item_to_group(group_id: $groupId, item_id: $itemId) {
     id
   }
}`;

const variables = {
  boardId: "1317064001",
  itemId: "1317064012",
  values: JSON.stringify({
   connect_boards5: {linkedPulseIds: [{linkedPulseId: 1316953659}]},
   date42: {date: "2023-11-30", time: "08:00:00"}, 
  })
};

await mondayClient.api(query, {variables});
1 Like

Yup it was really a formatting issue but using request-graphql really helps since it will auto cast where needed.

1 Like

something not to forget is monday’s API doesn’t adhere to the graphql spec regarding errors. It returns some errors according to the spec but many it creates error_message and error_code key in the response. I’ve brought it up several times but it seems to fall on deaf ears that having four different ways they return their errors breaks using spec compliant clients to their full capability.

2 Likes