Skip to content

Instantly share code, notes, and snippets.

@yuhgto

yuhgto/index.js Secret

Created April 24, 2020 03:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuhgto/16dc7dc327a281395766519598af8eb3 to your computer and use it in GitHub Desktop.
Save yuhgto/16dc7dc327a281395766519598af8eb3 to your computer and use it in GitHub Desktop.
monday.com API quickstart - Javascript
var fetch = require('node-fetch');
// Query 1: return a list of boards
let query = '{ boards (limit:5) {name id} }';
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
'query' : query
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
// Query 2: return items and column data for a single board
let query2 = '{boards(limit:1) { name id description items { name column_values{title id type text } } } }';
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
'query' : query2
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
// Query 2: Create a new item on a board
let query3 = 'mutation{ create_item (board_id:148203423, item_name:\"WHAT IS UP MY FRIENDS!\") { id } }';
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
'query' : query3
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
// Query 3: Create a new item, using variables
let query4 = 'mutation ($myItemName: String!) { create_item (board_id:148203423, item_name:$myItemName) { id } }';
let vars = {"myItemName" : "Hello, world!"};
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
'query' : query4,
'variables' : JSON.stringify(vars)
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
// Query 4: Create a new item and populate column values
let query5 = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:541328696, item_name:$myItemName, column_values:$columnVals) { id } }';
let vars = {
"myItemName" : "Hello, world!",
"columnVals" : JSON.stringify({
"status" : {"label" : "Done"},
"date4" : {"date" : "2020-08-27"}
})
};
fetch ("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization' : 'YOUR_API_KEY_HERE'
},
body: JSON.stringify({
'query' : query5,
'variables' : JSON.stringify(vars)
})
})
.then(res => res.json())
.then(res => console.log(JSON.stringify(res, null, 2)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment