Skip to main content

Node.js mutation example using Axios

  • July 12, 2019
  • 8 replies
  • 15811 views

kevinmarchese

If anyone familiar with Node.js wants to show an example of how to post to the new V2 Graphql api. Fetch or Request methods would be great as well.

This topic has been closed for replies.

8 replies

danielco
Forum|alt.badge.img
  • monday.com Team Member
  • July 17, 2019

Hi @kevinmarchese

Here’s a sample request to create an item in a board:

const axios = require('axios')
const body = {
  query: `
	mutation ($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) {
	  create_item (
	    board_id: $boardId,
	    group_id: $groupId,
	    item_name: $itemName,
	    column_values: $columnValues
	  ) {
	    id
	  }
	}
  `,
  variables: {
  	boardId: 1234567,
	groupId: "topics",
	itemName: "New item name",
	columnValues: JSON.stringify({ status: { index: 1 } })
  }
}
axios.post(`https://api.monday.com/v2`, body, {
    headers: {
      Authorization: 'API_TOKEN'
    }
  })
  .catch(err => {
    console.error(err.data)
  })
  .then(res => {
    console.log(res.data)
  })

kevinmarchese
  • Author
  • Participating Frequently
  • July 18, 2019

@danielco 🤩 I don’t even know what to say right now! Thank you of course! but its not enough for the time you saved me! I love yo…wait too strong. Seriously @danielco THANK YOU SO MUCH MAN!!!

Now that I know what I’m doing wrong and the correct structor I’m confident that I can figure the rest out based on this…so you gave me a great gift today and I hope one day I can at least pay it forward.


danielco
Forum|alt.badge.img
  • monday.com Team Member
  • July 18, 2019

Glad i could help 🙂
Let me know if you need more examples or have any issues


  • New Participant
  • July 30, 2019

Hello Daniel,
This particular example I can’t get working. I get this error:
{ errors:
[ { message: ‘Integer isn’t a defined input type (on $boardId)’,
locations: [Array],
fields: [Array] } ] }

-All i changed was board id, and added my api key


  • New Participant
  • July 31, 2019

Never Mind. there was a typo. It all works now.
This is the code that worked for me:

const axios = require(‘axios’);
axios({ url: ‘https://api.monday.com/v2’, headers: {
Authorization: myapikey
},
method: ‘post’,
data: {
query: mutation create_item($boardId: Int!, $groupId: String!, $itemName: String!, $columnValues: JSON!) { create_item ( board_id: $boardId, group_id: $groupId, item_name: $itemName, column_values: $columnValues ) { id } } ,
variables: {
boardId: 12345,
groupId: “Test”,
itemName: "New item ",
columnValues: JSON.stringify({ status: { index: 1 } })
}
}
}).then((result) => {
console.log(result.data)

})
.catch(function (error) {
console.log(error)
});

dipro
Forum|alt.badge.img
  • Leader
  • August 2, 2019

Thanks for posting your revised code! I’ve gone ahead and edited the original post to reflect the correct formatting.


kevinmarchese
  • Author
  • Participating Frequently
  • August 4, 2019

yes, I remember having to change to $boardId: Int! because it was just integer!, or something along these lines. It was close enough though to be very helpful.


dipro
Forum|alt.badge.img
  • Leader
  • August 6, 2019

I’m glad to hear it was helpful @kevinmarchese!