Change_multiple_column_values doesn't work as expected

Hi,

I’m trying to use change_multiple_column_values using Javascript:

let query5 =
'mutation ($boardId: Int!, $columnVals: JSON!, $itemId: Int!) { change_multiple_column_values (board_id: $boardId, item_id: $itemId, column_values: $columnVals) { id } }';
let vars = {
    boardId: boardId,
    itemId: itemId,
    columnVals: JSON.stringify(body),
};
      console.log(
        JSON.stringify({
          query: query5,
          variables: JSON.stringify(vars),
        })
      );
      fetch('https://api.monday.com/v2', {
        method: 'post',
        headers: {
          'Content-Type': 'application/json',
          Authorization: MONDAY_API_KEY,
        },
        body: JSON.stringify({
          query: query5,
          variables: JSON.stringify(vars),
        }),
      })
        .then((res) => res.json())
        .then((res) => {
         });....

When I’m using the MONDAY_API_KEY from my developer user, it ends with success.

But when I’m using the following token:
monday.get(‘sessionToken’).then((res) => {
setSessionId(res.data);
});
and send the sessionId instead of MONDAY_API_KEY, It ends up with an error message

Access to fetch at ‘https://api.monday.com/v2’ from origin ‘https://a053439f76c9.ngrok.io’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Any suggestion of how to perform such an update?
The problem is that when I’m using the MONDAY_API_KEY, all the activities are being saved under my user.

Hey @shaharsamira :wave:

Thanks for reaching out to us with this request and allowing us to help!

Just to make sure we’re on the same page here, you will not be able to avoid having API actions being associated with a user profile at this point in time. If you use your account’s API key, or even the short-lived tokens, the actions will still always be tied to a user profile within your account.

Does that help shed more light on this? I’ve gone ahead and passed your experience as feedback to our product team, as we are considering future adjustments. To be transparent with you, I am not able to commit to an ETA or even a rough timeline just yet, though.

-Alex

Hi @AlexSavchuk ,
Thanks for your answer.

All the monday.api mutations work as expected except ‘change_column_value’.
When I’m trying to achieve this by using monday.api(`mutation { change_column_value…
with a dynamic values and columns, It fails while trying to save, as the Graphql format is not as expected.

For example, assume I have JavaScript object as follows:

and the following code:
Array.forEach(arr => {
let id = arr.id;
let value = arr.value; // Or JSON.stringify(arr.value)
await monday.api(
mutation { change_multiple_column_values(item_id:${itemId}, board_id:${boardId}, column_id:\"${id}\", value:"${value}"){name}}
).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
})
});

The numeric value is being saved with a good format but the name type fails.

Do you have any idea or resource to find the best solution?
What’s the best practice for updating several item’s columns?
I’m developing an app using React & Node.js.

Thanks in advance.

Hi @shaharsamira!

Sorry for the delay in response-- we appreciate your patience.

From your forEach(), it looks like you’re making individual API calls to update each column. Instead, perhaps it might be easier to use the multiple column values call to update these all at once.

You can construct a new object from the original one that will contain the column Ids as keys and their relevant column values as values.

Here is an example:
let query5 = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:YOUR_BOARD_ID_HERE, item_name:$myItemName, column_values:$columnVals) { id } }';

let vars = { "myItemName" : "Hello, world!", "columnVals" : JSON.stringify({ "status" : {"label" : "Done"}, "date4" : {"date" : "1993-08-27"} }) };

Hope this helps!
-Helen

Hi @Helen,

It was very helpful, thanks.

1 Like

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