Mutation for each column value of a given item/pulse

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.

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:

1 Like

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

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: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

What do you think?

1 Like

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-monday.com 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) 
});
})
}

Hi @dipro-monday.com 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