Node.js Change multiple column values

I am using Zapier to create a new Monday pulse everytime a specific action happens in my CRM. The problem is that zapier only allows access to the pulse title so all my data is dumped in the title. I have created a node.js script that parses out the desired information and then mutates multiple column values you move that data into the appropriate column. I can’t for the life of me get it to work and the documentation is not helping. Any help would be appreciated.

Here is my index.js file:
const express = require(‘express’)
const path = require(‘path’)
const bodyParser = require(‘body-parser’)
const PORT = process.env.PORT || 5000

const updateMultipleColumnValues = require("./updateMultipleColumnValue").updateMultipleColumnValue;




const app = express();
  app.use( bodyParser.json());
  app.use(bodyParser.urlencoded({extended: true}));
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'ejs');
  
  app.post('/', (req, res) => {
    console.log(req.body)
    const { boardId, pulseId } = req.body.event
   
      let parsedRecord = extractData(req.body.event.pulseName)
      console.log(parsedRecord);

      let newData = {
        "text0": parsedRecord.DURATION
      } 

      let stringData = JSON.stringify(newData);

      console.log(boardId);
      console.log(pulseId);
      console.log(stringData);
      updateMultipleColumnValues(boardId, pulseId, stringData);
    res.json(parsedRecord)
  });

  app.listen(PORT, () => console.log(`Listening on ${ PORT }`));



function extractData(str) {
  let fields = ['DATE', 'TIME', 'DURATION', 'TYPE'];

  return str.split(/\s*\|\s*/).reduce((res, entry) => {
    let dat = entry.split(/\s*:\s*/);
    return fields.indexOf(dat[0]) > -1 ? Object.assign(res, { [dat[0]]: dat[1] }) : res;
  }, {});
}

and here is my update column script
const executeMondayQuery = require("./executeMondayQuery").executeMondayQuery;

const updateMultipleColumnValue = async (boardId, itemId, newData) => {
  const updateColumnValueBody = {
      query: `mutation {
      change_multiple_column_values(
      board_id: ${boardId},
      item_id: ${itemId},
      column_values: ${newData}
      ) { id }
    }`
  };

  await executeMondayQuery(updateColumnValueBody);
};

exports.updateMultipleColumnValue = updateMultipleColumnValue;

Hello, I won 't get into the details of your code, but I can give you a general suggestion: Try dumping the content of the query you generated and try it on: https://monday.com/developers/v2/try-it-yourself.

Do you receive a specific error from the api endpoint ?

Hope it helps,
Gianluigi

This is the error I am receiving. But in the docs it says if you’re using javascript to stringify the output, why is it not working?
{
“errors”: [
{
“message”: “Parse error on “date4” (STRING) at [5, 23]”,
“locations”: [
{
“line”: 5,
“column”: 23
}
]
}
],
“account_id”: 2115812
}

If you could inspect your column data as serialized by JSON.stringify(), it would help understand your issue. Can you share it with us ?

I had a similar problem trying to just write a single value with change_column_value. I eventually got it to work by passing in a GraphQL variable and used JSON.stringify on the variables parameter and that seems to make the API happy. In the example below I’m suggesting you treat your newData the way I’m treating the variable value.

const body = {
  query: `
    mutation ($textValue: JSON!){
      change_column_value(
        board_id: ${boardId},
        item_id: ${itemId},
        column_id: ${colId},
        value:$textValue
      ){
        id
      }
    }
    `,
  variables: {
    textValue: JSON.stringify(value),
  },
}

@Tod Thank you!
I had the same problem trying to update a single column date value.
Somehow these two implementations don’t work:

json: true,
body: { query:
  `mutation {change_column_value(
      board_id: 394002736,
      item_id: ${result.body.data.create_item.id},
      column_id: "date",
      value: JSON.stringify({"date": "2019-06-03"})
) { id }}`
body: JSON.stringify({ query:
  `mutation {change_column_value(
      board_id: 394002736,
      item_id: ${result.body.data.create_item.id},
      column_id: "date",
      value: JSON.stringify({"date": "2019-06-03"})
) { id }})`
1 Like

@Zalayeta – did your query work when you tried it in our GraphQL explorer? Here’s the link: https://monday.com/developers/v2/try-it-yourself