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.
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)
})
@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.
Glad i could help
Let me know if you need more examples or have any issues
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
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)
});
Thanks for posting your revised code! Iāve gone ahead and edited the original post to reflect the correct formatting.
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.
Iām glad to hear it was helpful @kevinmarchese!