Difficulty updating tags on item

Hello,

Having major issues updating the tag on an item column. I’ve tried various things but no luck. It appears that some value is being populated in the tag field, but not the actual tag. In monday, the field gains the little “+” symbol when this code runs, but nothing is visible. When I right click, I can “clear values” and the “+” disappears.

Updating other columns using this function works fine. Just the tags is an issue. I don’t get any errors. I’ve tried various things some below:

        "tags__1": { tag_ids: [929292] },
        [tags__1]: { tag_ids: [929292] },
        "tags__1": { tag_ids: ["929292"] },

Here’s my code. Please help!

async function updateItem() {
try {
const response = await fetch(“https://api.monday.com/v2”, {
method: “post”,
headers: {
“Content-Type”: “application/json”,
Authorization: mondayAPI,
},
body: JSON.stringify({
query: mutation ($myBoardId: ID!, $myItemId: ID!, $myColumnValues: JSON!) { change_multiple_column_values(item_id: $myItemId, board_id: $myBoardId, column_values: $myColumnValues) { id } } ,
variables: {
myBoardId: “6775681461”,
myItemId: “6791619434”, // Replace with your actual item ID
myColumnValues: JSON.stringify({
“tags__1”: { tag_ids: [929292] },
// [“numbers”]: “123”,
}),
},
}),
});

if (!response.ok) {
  throw new Error(`HTTP error! status: ${response.status}`);
}

const data = await response.json();
return data;

} catch (error) {
console.error(“Error updating item:”, error);
return error;
}
}
const updatedItem = await updateItem();

So something to remember is that monday may not return an HTTP error for all GraphQL errors.

Instead you need to check the actual response for an errors object, an error_code string, or error_message string. Those will be the real graphql errors.

I bring this up because you’re not checking these in your code. At this time if the response.data object is undefined you can presume there are errors and log them. In the future it may be null or an empty object on error depending on the error. But for now if its undefined there are GraphQL errors.

1 Like

Good point, thanks, I’ll add some code to look at the response.

I’ve added the code, but no errors there in the response…

Darn. But hey, at least we know its NOT returning an error. I want to double check the board isn’t private/sharable? Tags have context - private/sharable tags are stored in the board itself and aren’t available to other boards. Public tags are available globally - but I don’t believe can be used on private boards.

Also what happens if you read the column value back by API?

Thanks for your help!

I read the value of the tags column for two items. One where I set the tag via API and one where I set it in the browser.

The issue was that I didn’t realise you had to create the tag, give it a name, and get its ID, before updating a column with a tag ID.

I thought that a tag just had a value, at that the value given to it was its ID and its name.

I now have it working, but have noticed that I have to refresh the browser to see the updated tag name in the column. (Using chrome).

Ah, thats where I would go next, I was assuming you were using a tag ID you’d already gotten from someplace else.

The refreshing browser seems to be something that happens with API based changes not propagating to the browser sometimes. For that I don’t have any answers.