Change_multiple_column_values call returning 200 but not updating Item

Hi,

I’m trying to use the monday API to update an item based on an update to a GitHub issue (i.e. if a label is added to a GitHub issue, add it to list of labels in its corresponding Monday item).
I’m getting a 200 from the call, but I’m not seeing the changes reflected in Monday.
The fetch call:

const targetBoardId = 111111;
const targetItemId = 22222;
const updateItemResp = await fetch('https://<enterprise_domain>.monday.com/v2', {
  method: 'post',
  headers: {
    'Content-Type': 'application/json',
    Authorization: shortLivedToken // This is all within an integration recipe, so grabbing auth from there
  },
  body: JSON.stringify({
    query: 'mutation ($targetBoardId:Int!, $targetItemId:Int!, $newColumnValues:JSON!) { change_multiple_column_values(item_id: $targetItemId, board_id: $targetBoardId, column_values: $newColumnValues) { id } }',
    variables: JSON.stringify({
      targetBoardId, 
      targetItemId,
      newColumnValues: JSON.stringify(columnValues),
    }),
  }),
}).then((res) => {
  console.log(res);
  return res;
})
.catch((err) => {
  console.log(err);
});

For reference here is an example of what I’m passing as columnValues:

{
  status: 'Open',
  dropdown2: 'bug,duplicate,good first issue',
  link: 'https://www.github.com/user/example-repo/issues/7 Test Issue #7',
  date: null,
  numbers: 7,
  dropdown: 'Feature',
  people_1: '1234567,1234568'
}

When I try the same mutation in the playground I’m able to successfully update and see the changes reflected in the Monday item, but not so through my Monday app. Any suggestions?
FYI I’m building my app following the example from this repo: welcome-apps/apps/github-node at master · mondaycom/welcome-apps · GitHub
Thanks!

hi @akumar195
As long as there are no protocol errors you will always receive a 200 return value. You have to inspect the respons if it contains errors. See also Error Codes.

Hi @basdebruin thank you for replying so quickly!
I was taking a look at the response by logging it to the console within the then() function but it wasn’t too helpful:

  size: 0,
  timeout: 0,
  [Symbol(Body internals)]: {
    body: Gunzip {
      _writeState: [Uint32Array],
      _readableState: [ReadableState],
      readable: true,
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: true,
      allowHalfOpen: true,
      _transformState: [Object],
      _hadError: false,
      bytesWritten: 0,
      _handle: [Zlib],
      _outBuffer: <Buffer 7b 22 64 61 74 61 22 3a 7b 22 63 68 61 6e 67 65 5f 6d 75 6c 74 69 70 6c 65 5f 63 6f 6c 75 6d 6e 5f 76 61 6c 75 65 73 22 3a 7b 22 69 64 22 3a 22 31 37 ... 16334 more bytes>,
      _outOffset: 0,
      _chunkSize: 16384,
      _defaultFlushFlag: 2,
      _finishFlushFlag: 2,
      _defaultFullFlushFlag: 3,
      _info: undefined,
      _maxOutputLength: 2147483647,
      _level: -1,
      _strategy: 0,
      [Symbol(kCapture)]: false
    },
    disturbed: false,
    error: null
  },
  [Symbol(Response internals)]: {
    url: 'https://<enterprise_domain>.monday.com/v2',
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: 0
  }
}

I also tried using the monday-sdk-js npm package from the dependencies in the repo I linked. The method below threw a little bit more informative error but wasn’t too helpful either. Seems I’m just formatting the body incorrectly but not exactly sure what the issue is.
The code:

      mondaySdk = require('monday-sdk-js');
      const mondayService = mondaySdk();
      mondayService.setToken(shortLivedToken);
      const updateItemResponse = await mondayService
        .api(
          `mutation {
            change_multiple_column_values(item_id: ${targetItemId}, board_id: ${targetBoardId}, column_values: ${JSON.stringify(JSON.stringify(columnValues))}) 
            // Serialize columnValues twice since it seems in the documentation/repo the API is expecting a JSON string with the quotation marks escaped (\"key\":  \"value\"... ) 
            { id }
          }`
        )
        .then((res) => {
          console.log(res);
        })
        .catch((err) => {
          console.log(res.status);
          console.log(err);
        });
    }

And the error:

{
  errors: [
    {
      message: 'Parse error on "status" (STRING) at [2, 102]',
      locations: [Array]
    }
  ],
  account_id: 8885037
}

For this sdk method I followed the example as best I could here: GitHub - mondaycom/monday-sdk-js: Node.js and JavaScript SDK for developing over the monday.com platform

Hello @akumar195,
Using the sdk, there is no need to stringify the column values twice. That may be the reason for the error.
Try this

const updateItemResponse = await mondayService
        .api(
          `mutation {
            change_multiple_column_values(item_id: ${targetItemId}, board_id: ${targetBoardId}, column_values: ${JSON.stringify(columnValues)}) 
            // Serialize columnValues twice since it seems in the documentation/repo the API is expecting a JSON string with the quotation marks escaped (\"key\":  \"value\"... ) 
            { id }
          }`
        )

Or even better, you can try this

const variables = {
    boardId: +targetBoardId
    itemId: +targetItemId,
    columnValues: JSON.stringify(columnValues),
  };
const updateItemResponse = await mondayService
        .api(
          `mutation change_multiple_column_values($boardId: Int!, $itemId: Int!, $columnValues: JSON!) {
    change_multiple_column_values(board_id: $boardId, item_id: $itemId, column_values: $columnValues) {
      id
    }
  }
    `,
    { variables }
        )

Your second example worked! I had tried every manner of serializing the columnValues object (once, twice, no serialization) but seems beyond that the way I was calling the mutation function was incorrect as well…
Thank you for the help!

2 Likes

Hey @akumar195,

I’m glad that our amazing community experts @kolaai and @basdebruin were able to help you find the solution here :slight_smile: That’s amazing!

Thanks so much for your help here, I really appreciate it.’

-Alex

1 Like

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