Mutation for each column value of a given item/pulse

Moderator edit: we now have quickstart guides that walk new users through this. Here are links to our guides in Python, PHP and Javascript.

I’d like figure out how to set up a mutation call to post an entire pulse and its column values. In the documentation it says the argument should take “column_valuesJSON” however I’m wondering how to configure this correctly. Would it be in the following configuration, or do you have to create the item, then a PUT call for each column_value? Thank you for feedback here.

mutation {

create_item (board_id: 20178755, group_id: "today", item_name: "new item", column_values: {???} ) {

id

}

}

I will post to this once I find the correct way of doing this, but if anyone has a good example, please share, it will save me tons of time.

I would think you have to create the item/pulse first.

1 Like

3 hours later…Works!

mutation {
  change_column_value(item_id: HERE, column_id: "text", board_id: HERE, value: "\"ready 3\"" ){
    id
  }
}

Hey,
you can also use the create_item mutation to set the column values in one action instead of creating it and then using change_column_values (which also works).
Try the create_item mutation with the column values you want to set in the column_values parameter just like you did with change_column_values, like so:

mutation {
    create_item (board_id: 20178755, group_id: "today", item_name: "new item", column_values: "{\"text\": \"ready 3\"}" ) {
        id
    }
}

This way you can also set multiple columns in one API call, lets say you also want to set a status column:

mutation {
    create_item (board_id: 20178755, group_id: "today", item_name: "new item", column_values: "{\"text\": \"ready 3\", \"status_column_id\": {\"id\": 2}}" ) {
        id
    }
}

Let us know if it works for you :slight_smile:

2 Likes

Thank you so much for the examples here!!! that is great to see. I will try this sometime today and let you know how it goes.

I guess in whatever language someone uses, in my case node.js I would just JSON.stringify whatever input needs to go with the axios request?

so quick question here if you don’t’ mind, what sound more correct? do you have to set a variable to stringify or simply add JSON.stringify (“input”) to the arguments.

let answer = JSON.stringify({
  "text": "Sample text"
});

or would you simply add to the arguments

mutation {
    create_item (board_id: 20178755, group_id: "today", item_name: "new item", column_values: JSON.stringify("input") ) {
        id
    }
}

mutation {
    create_item (board_id: 20178755, group_id: "today", item_name: "new item", column_values: answer ) {
        id
    }
}

or I’m I way off base with each? Thank you for helping a nood out. I’m very green to graphql

1 Like

Hey Kevin!

Great question. The actual content in your query is evaluated on the GraphQL server, so you can’t include JS functions like JSON.stringify() within the parameters of your query. There are a couple of ways you can get around this:

  1. The GraphQL way: send the column data as a GraphQL variable: https://graphql.org/learn/queries/#variables

  2. Assign a variable in your program with the stringified value (let foo = "bar"), and then use a template string to refer to that variable inside your query. Check out this link for more information on template strings: Template literals (Template strings) - JavaScript | MDN

What do you think?

2 Likes

Dipro,

Thank you so much! :clap: This will allow me to be on the correct path and focus my efforts to get to my goal. I very much appreciate the hand holding here lol. You all are very much above and beyond as I know this isn’t your deal to help in these kind of cases. So very thankful. I feel though that if I want to do it, then it’s likely that others would as well and so this documentation with hopefully help someone on my level out as well. specific examples that I post here are for me and others who may benefit from such specific examples.

So if I figure something specific out I will def post a specific example to it, not only for my reference but to also allow others to pick up quicker than I.

1 Like

@dipro would you please let me know if I’m just being stupid here…or if this is fundamentally wrong. I know it must look like a 1st graders drawling that you put on the fridge :smile: but i’m really trying to figure why I’m getting parsing errors here in the many ways I’ve tried to get this to work, am i on the right track here and just need further understand? I’m cool with that but if this is way off base let me know, pls. thank you well in advance!

  var boardid = 20178755 ;
  var groupid = "today" ;
  var itemname = "new item" ;
  
  var id = JSON.stringify(boardid); 
  var group = JSON.stringify(groupid); 
  var item = JSON.stringify(itemname); 
  
  console.log(id)
  
  axios({
  url: 'https://api.monday.com/v2',headers: {
       Authorization: 'Bearer ' + process.env.mondayToken
     },
  method: 'post',
  data: {
      query: `
         mutation 
            create_item ( $board_id: ${id} , $group_id: ${group} , $item_name: ${item} ) { 
               id
            
        }`
  }
  }).then((result) => {
     console.log(result.data);
        
  
  })
    .catch(function (error) {
    console.log(error) 
});
})
}
1 Like

Hi @dipro I have a couple more things I’m wanting to try to get this to work since posting the above code however if you wouldn’t mind taking a look and just letting me know if it kinda the right track? or just plain wrong in every sense of the word haha.

So you have to in some way stringify the inputs. so could it just be

 var a =   {"board_id" : "20178755",
      "group_id" : "today",
       "item_name" : "input"
    }

var b = JSON.stringify(a);

then create_item ( $board_id: ${board_id} , $group_id: ${group_id} , $item_name: ${item_name} )

is the above closer to what is needed? ever grateful for input :slight_smile: :pray:

hey @kevinmarchese,
no need to JSON.stringify the values that are not JSON type, you can simply add the quatation marks when the value is a string.
Going with the code you sent, this should work (group_id and item_name are strings while board_id is an int):

data: {
      query: `
         mutation 
            create_item ( board_id: ${id} , group_id: "${group}" , item_name: "${item}" ) { 
               id
            
        }`
  }

another approach I can suggest the use of graphql variables.
try this:

  var boardid = 20178755 ;
  var groupid = "today" ;
  var itemname = "new item" ;
  
  console.log(id)
  
  axios({
  url: 'https://api.monday.com/v2',headers: {
       Authorization: 'Bearer ' + process.env.mondayToken
     },
  method: 'post',
  data: {
      query: `
         mutation ($board: Int!, $group: String!, $name: String!) {
            create_item ( board_id: $board , group_id: $group , item_name: $name ) { 
               id
           }
        }`,
      variables: {
          "board": boardid,
          "group": groupid,
          "name": itemname,
      }
  }
  }).then((result) => {
     console.log(result.data);
        
  
  })
    .catch(function (error) {
    console.log(error) 
});
})
}

@Ayelet Thank you, thank you, thank you :smile: you guys are on fire today!! I can’t thank you enough for this and the time it has saved me! I thank you from the bottom of my heart. You guys are seriously awesome. Thank you once again for this which I consider a gift. From this I can know if the structure is right and apply this else where so thankful for that. :pray:

1 Like

Hello Monday Team,
I need to change status of column for variable pulses and use unique Monday pulse id : item_id to find the line. The code below works fine when I use fixed number as item_id in query, but i receive error when i try to make the item_id variable.

<?php $tempUrl = 'https://api.monday.com/v2/';
$ch = curl_init();
$token = 'xxxxxxxxxxx ;
$item_id = "324602024" ;
$query = '
mutation ($item_id: Int! ) {
change_column_value (board_id: 310254178, item_id: $item_id, column_id: "status9", value: "{\"index\": 1}") { id } }
'
;
$headers = ['Content-Type: application/json', 'User-Agent: [whatpresents] GraphQL Client', 'Authorization: ' . $token];
$data = @file_get_contents($tempUrl, false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => $headers, $content = json_encode(['query' => $query , 'variables' => [ 'item_id' => $item_id ]
]), ] ]));
$tempContents = json_decode($data, true);

i receive error {“message”:“Variable item_id of type Int! was provided invalid value”,“locations”:[{“line”:2,“column”:11}],“value”:“324602024”,

i try to understand what I do wrong, and very appreciate if you could have a look
Thanks !

to re-phrase my question: if we use example from documentation:
mutation {
change_column_value (board_id: 20178755, item_id: 200819371, column_id: “status”, value: “{“index”: 1}”)
{id} }

how to make " item_id " variable ?

Hello guys,
I am facing a similar issue when trying to create a new item with some column_values values.
image
The item gets created but the column_values are completely ignored.
Can anyone point in the right direction?
Thanks

Hi Monday Team , could you please advise something ?

hey @alextop,
this is how you add variables to the change_column_value mutation:

query: `mutation ($item_id: Int!){
         change_column_value(item_id:$item_id, column_id: "status9", board_id: 310254178, value: " 
         {\"index\": 1}"){
            id
         }
        }`,
variables: {
  "item_id": 123456
}

hey @jnet06,
I think this is a different issue. You need to use the column id and not the column title.
Please run this query to get the column id:

query{
  boards(ids: 999999){
    columns{
      settings_str
    }
  }
}

thank you Ayelet, I will try it later today,

That was the problem, thanks so much Ayelet! :slight_smile:

Hello Ayelet, thanks a lot !!!
Eventually the issue is fixed with your help,
many thanks again !