Update an item on a board

wow it worked finally jeez thank you @basdebruin :+1: :1st_place_medal: :trophy:

@enlightened we were supposed to stringify a STRING to be passed in as the value. Setting $value as String! type or setting the value to a primitive string won’t work cause $value must be JSON, apparently

So try this:

const query = `mutation change_column_value($value: JSON!) {
       change_column_value (board_id: 218918653, item_id: 551681223, column_id: "text21", value: $value) {name}}`

await monday.api(query, {variables: {"value": JSON.stringify("SAMPLE")}})

Hey @supernova ,

sorry I should be more precise in such a case.
Let’s say we want to change a column value of a Long Text Column.
In the documentation, Column-Value-Section, you can see how your String has to be formated.

It would look like this:

const query2 = `mutation change_column_value($value: String!) {
      change_column_value (board_id: 726291451, item_id: 726291453, column_id: "long_text", value: $value) {id}}`;

const variables = "{\"text\" :\"Sample\"}";

monday.api(query2, { variables }) 

If you want to add a JSON and don’t want to format it by hand you need to pay attention to your input. It would look like this:

const query2 = `mutation change_column_value($value:JSON!) {
      change_column_value (board_id: 726291451, item_id: 726291453, column_id: "long_text", value: $value) {id}}`;

const variables = JSON.stringify({ 
        "text": "Sample"
 });

monday.api(query2, { variables })

Hope that helps.

2 Likes

Since I’m doing this from one of our web servers (IIS) I’m using a POST call like this:

set xmlhttp = server.Createobject(“MSXML2.ServerXMLHTTP”)
xmlhttp.Open “POST”,“https://api.monday.com/v2/”,false
xmlhttp.setRequestHeader “Authorization”, strToken
xmlhttp.setRequestHeader “Content-Type”, “application/json”
xmlhttp.setRequestHeader “Accept”, “application/json”
xmlhttp.send(str)

I’m still trying to figure out how to put a mutation with a variable in one string. I think this is correct:

str=“{ “query” : “mutation change_column_value($value: String!) {change_column_value(board_id:218933653, item_id:551622223, column_id: “text21”, value: $value) {name} }” }”

But I not sure where to put the value of the string variable. This DOES NOT work:
str=“{ “query” : “mutation change_column_value($value: “SAMPLE”) {change_column_value(board_id:218933653, item_id:551622223, column_id: “text21”, value: $value) {name} }” }”

Hey @enlightened :wave:

I’m glad to join in on the help party here! I’ll have to take a further look with the team to see what might be the root cause for this behavior and I’ll get back to you as soon as I can with more pointers :slight_smile:

That said, I am literally speechless at the amount and quality of help that @supernova, @basdebruin and @TMNXT-Dev have provided here!! Thank you so much for being an active pillar of our community and for helping our users where they need more support the most.

-Alex

2 Likes

The others brought up a good point about stringifying your JSON and I really think that is the main problem as well. Since you’re using XMLHttpRequest rather than Monday’s API, the requirement is a bit different. Moving forward I recommend using JSON.stringify() than try to figure out where to put the slashes and quotes. insert whohastimeforthat.gif
I believe you wanted to use it all in one line and stick your variables inside the query and not use variables, but unfortunately that’s not possible with changing column values as @supernova and @TMNXT-Dev have pointed out.

I have it working for XMLHttpRequest here:

The query:

const query = `mutation changeValues($board_id: Int!, $item_id: Int, $column_id: String!, $value: JSON!) {
        change_column_value (board_id: $board_id, item_id: $item_id , column_id: $column_id, value: $value) {
          id
        } 
      }`

The variables:

//The JSON.stringify() your value way

const variables =  {"board_id": boardId, "item_id": itemId, "column_id": "status", "value": JSON.stringify({index: 2})}

//Stringify the value yourself way:

const variables =  {"board_id": boardId, "item_id": itemId, "column_id": "status", "value": "{\"index\": 2}"}
      

I’m not familiar with IIS, but I am a bit familiar with XMLHttpRequests as I use fetch more frequently, so I hope you can translate it to how you want, but this is how I have it working:


      const xmlhttp = new XMLHttpRequest();
      const theUrl = "https://api.monday.com/v2"

      xmlhttp.open('POST', theUrl);
      xmlhttp.setRequestHeader("Content-Type", "application/json")
      xmlhttp.setRequestHeader("Authorization", token)

      //Yep, stringify it again.
      xmlhttp.send(JSON.stringify({query, variables}))

Hope that helps you get pass this issue! If not, let us know.

2 Likes

Hmm…

This works great via the https://monday.com/developers/v2/try-it-yourself:

mutation {change_column_value(board_id:XXXXXXXXX, item_id:YYYYYYYYY, column_id: “text21”, value: “"some text"” ) {id name}}

So it stands to reason this exact string (str) should work via POST to

set xmlhttp = server.Createobject(“MSXML2.ServerXMLHTTP”)
xmlhttp.Open “POST”,“https://api.monday.com/v2/”,false
xmlhttp.setRequestHeader “Authorization”, strToken
xmlhttp.setRequestHeader “Content-Type”, “application/json”
xmlhttp.setRequestHeader “Accept”, “application/json”
xmlhttp.send(str) or xmlhttp.send(JSON.stringify(str))

Neither work. And I’m not sure why using variables would have any effect if this string works fine inside the try it yourself area.

Hello @enlightened
I believe it would have to be

xmlhttp.send(JSON.stringify({query: str}))

as str is your query, correct? I should have made that clearer.

As for variables. You’re right and as discussed in @supernova’s post earlier: Can't change column value(s) Unfortunately the only way to get it working is with variables. May be a bug or if it’s not, the documentation should stress it more that variable is required. nudge @AlexSavchuk nudge

So if you’re going to add variables, you’ll just need to send it this way:

xmlhttp.send(JSON.stringify({query: str, variables: yourVariables}))
2 Likes

If you’re open to suggestions @AlexSavchuk , here are some that I have for monday’s current API doc:

  • where Playground is first introduced, specify that just because a query runs successfully in the GraphQL editor does not mean that that same query will work in code ( also a good place to clearly state requirement of variables* here )

    *maybe also emphasize variables usage at relevant checkpoints throughout the doc for those who don’t attentively read from A-Z… lol (me)

    anchor links or even a :warning: will do  :+1:


  • under   Mutating > Columns > Change column values :

    I suggest including another example for a simple Text column ( and/or add a section for   Text Column   to the list of column types under “Changing column values section” )

    cuz right now it’s not intuitive (to me at least) from what’s given that you have to convert a ~ string ~ to JSON for a Text column. Long Text + Status col inputs (status is the default example in the doc) scream Object! to a newbie. Since updating an item’s text is such a common use case, I feel like it deserves its own special place on the doc y’know?


  • include more concrete, practical, thorough examples

    something like this:

    const jsonStr = JSON.stringify(
      {
        text: "success", 
        status: {
          label: "Done"
        }
      });      
    
    const jsonStr2 = JSON.stringify(
      {
        text: "hooray!",
        status: {
          index: 1
        },
        date7: {
          date: "2020-09-10",
          time: "13:25:00"
        },
        email_1: {     
          email: "itsmyemail@mailserver.com",
          text: "my email"
        }, 
        link: {
          "url": "http://monday.com",
          "text": "go to monday!"
        },
        numbers_3: "110.95",
        long_text_1: {
          "text": "Hi, I'm a Long Text! I can contain up to 2000 chars! Text is my twin...what's her char limit, you ask? Idk! Sadly, our creators never told us ¯\_(ツ)_/¯ But hopefully we'll find out soon enough so we can let you know :p Anyway, try me out! Click add column > more columns & you'll find me there!"
        }           
      });
    

        reads better than this:

        {\"text\": \"success\", \"status\": {\"label\": \"Done\"}}


I know there's a section near the end laying out both forms for each individual col type (excluding text). That's great! But it'd be *even more* helpful, compact & comprehensible imo to have a complete example that demonstrates how to **Change multiple column values** as a quick one-stop reference point.

That way, whenever someone wants to update multiple column values together, s/he won’t have to jump to another section to collect the info needed. It’d be clear right off the bat which key/value pairs & types are expected for which column types.


Also, ( somewhat minor but still relevant I guess ) :

For argument types where we see !Int , !String , !JSON, the exclamation points are there to indicate that those args are required, right? Except at first sight, it reads the opposite! I’m sure this one’s a typo & ! should be at the end. Just interesting that a misplacement of 1 char can completely flip the intended meaning haha again, nbd since it’s easy to deduce from the given context.

Still, I think it’s worth pointing out since I do recall being confused about this very early on. And if someone misinterprets !JSON to mean that JSON is optional…well then you can see the trouble there. That alone may throw them off when their query doesn’t run in code as they expect it to.


TL;DR

emphasize variables requirement; add text column example; the more examples the merrier :partying_face: :balloon:


Just my 2¢ :sparkles:
:slightly_smiling_face:

2 Likes

Got fired up by your post & drafted up a whole proposal :hot_pepper: @pepperaddict lol :joy:

2 Likes

Hey awesome community people @enlightened, @pepperaddict and @supernova!

Thanks for staying on this case and making sure we can figure this out together! I really appreciate your continued support :hot_pepper: and :shark: - your contributions to the community have been just top-notch lately. Honestly, thank you for taking the time out of your day to help other users out :slight_smile:

I’ve taken a further look at this with the team, and we have come to the conclusion that the values you are trying to send to our servers are not formatted as JSON correctly, which is why they’re getting blocked with an error:

To me, it seems like you are applying the JSON.stringify in a way that shouldn’t work with our API, especially seeing as some columns, like the Text column, have a different structure to their data than others.

This is what I am referring to when saying the JSON.stringify code could be used in a better way:
variables: JSON.stringify({“value”: “SAMPLE”})

Instead, it should be
variables: JSON.stringify({“value” : JSON.stringify(“SAMPLE”)})

Overall, the isn’t going through as expected because at this point in time, our column value parser expects JSON values (not primitives) in most cases, which is something that @supernova is referring to in his post as well. This means that even if the value you are sending is a string of text to a Text column, the whole string has to be formatted as JSON for the platform to recognise it as such. Does that make sense?

That said, I do think this is a point of friction and tension for a lot of our users, as I have issues with this exact process myself. To be transparent with you, we are already working on making further improvements to this area and I want to make sure this thread is not lost in the community - I’ve passed it on to the development team just to show how big of an impact this current setup has on our users.

@supernova

I really appreciate you coming forth with a list of suggestions that would make our users’ life with code easier, as creating apps and integrations is not an easy task to begin with. I’m stunned by the time you’ve put into making sure your experience is taken into account and I definitely agree that the documentation needs some love from our team to make it clearer, easier to use and more intuitive.

I’m afraid I can’t commit to an ETA when the changes you are looking for would become more than suggestions and be implemented in practice, but I’ve taken those points to the team and hopefully, we can make an effort together to make this part of the platform better. Again, I appreciate your awesome, friendly and clear input with action steps, as this helps us make those changes in a quicker way as well.

-Alex

2 Likes

hey @AlexSavchuk , I appreciate the update

For Text column, this works as well:

variables: {"value": JSON.stringify("SAMPLE")}

I guess what we were trying to get across is that we wished the documentation could’ve been clearer with better examples. Ultimately, we were able to get the queries to work, but it wasn’t until we discovered that we had to use variables (kudos to :hot_pepper:). And from there the struggle then became figuring out exactly how to structure the variables so they’d pass. This is but one case where updating the docs could save a lot of time and frustration - not just for users of this platform but for monday’s development team as well. I suspect there would be less cases of confusion over simple things like this, eliminating the need for multiple back and forth exchanges surrounding some core piece of information that could have & should have been better explained in the doc.

Anyway, I typed out that lengthy post (surprised myself too, smh) not just to share my own account + a few others’ I’ve seen on this forum, including @enlightened’s from this discussion, but primarily to shed light on how frustrating it can be from a new dev’s perspective. And because I believed the few starter suggestions I listed shouldn’t take long to implement. Any one of the working solutions or examples provided in this forum could literally be copied & pasted, and that would already count as an improvement. It’s bad enough to struggle through something firsthand; even worse to witness someone else fall into the same trap - stuck for what could be hours, days, or worse yet, giving up entirely - when something like this could easily have been avoided with just a few lines edited / highlighted in the doc. This is why it bothers me as much as it does. But I also understand that y’all may have your priorities set elsewhere at this time.

Well, at least now this thread exists for future new users to reference if they know what to search, so that’s a start! Anyway, it’s awesome that you’ve acknowledged this pain point & plan to someday improve the docs :+1:

:sparkles: All the best! :sparkles:

1 Like

I completely agree with :dolphin:!
More examples will definitely help and this is the third post regarding this issue (that I’m aware of) .

Thank you @AlexSavchuk for getting back to us regarding this!

Sorry for hijacking this post, and please don’t take this the wrong way: I feel like the problem we’re facing is being overlooked as a json issue. Which may still be a possibility but we’ve tried different approaches and the frustration mostly lies on it working in playground but not in practice.

The thing is… Having variables work:

      const query = `mutation changeValues($board_id: Int!, $item_id: Int, $column_id: String!, $value: JSON!) {
        change_column_value (board_id: $board_id, item_id: $item_id , column_id: $column_id, value: $value) {
          id
        } 
      }`

      monday.api(query, {variables: {"board_id": boardId, "item_id": itemId, "column_id": "status", "value": "{\"index\": 1}"}})

but plugging the value into the query doesn’t:

      const query = `mutation {
        change_column_value (board_id: 123 , item_id: 1234 , column_id: "status", value:  "{\"index\": 1}" ) {
          id
        } 
      }`

      monday.api(query)

When working with enlightened’s xmlhttp post request, I also had to use variables to be able to successfully update the column so it’s not just a Monday SDK issue. Well, whether it’s a bug or not, :dolphin:'s suggestion of having more examples will make any developer happy. haha.

1 Like

:sparkles: Exactly :sparkling_heart::green_heart: :sparkles:

Just did a quick search & these are the sort of cases I was referring to:


Also, I remember responding to someone’s post in discord about having better documented integration & recipe examples. Not sure if our comments were even seen though 🤷🏻‍♀️
2 Likes

@AlexSavchuk If the team ever needs inspiration, I recommend checking out Chainlink’s dev docs + resources. Although they’re blockchain focused in the cryptosphere, you can still get good ideas from their dev docs (e.g. use of multi-tab editor to demo query code samples in different programming languages) :+1:

( sry this is the last time I’ll bug you about this stuff aha srsly I’m getting tired too :stuck_out_tongue_closed_eyes:
plz don’t take offense at any of this :pray: )

2 Likes

Can we update an item without knowing item_id.
I am creating a duplicate board.
After duplicating it I need to set some values from webhook.
But Now I don’t about the item_id of it but I know name will always same.
Can Anybody help?

@discobot @basdebruin @enlightened Can anyone help?

Hi! To find out what I can do, say @discobot display help.

@Manu

That’s an interesting use case for sue!

At the time, you will always need to have an Item ID in order to update a specific item. That said, how is the board being created? Would querying for the items of the board and then fetching the IDs work for you?

-Alex

This thread is getting too long for a new user to find their answer, so I’m going to close it. If you have questions about updating items, please open a new topic with your question! Thank you.