I’m really struggling with syntax and formatting in google app script. As a baseline, this works for creating an item on a board:
const BASE_URL = 'https://api.monday.com/v2';
const dealBoardId = '5533299122'; //Deals board in the test workspace
function createMondayDeal() {
let query = 'mutation ($myItemName: String!, $columnVals: JSON!) { create_item (board_id:' + dealBoardId + ', item_name:$myItemName, column_values:$columnVals) { id } }';
let vars = {
"myItemName": "Hello, Best Deal!",
"columnVals": JSON.stringify({
"deal_stage" : {"label" : "New"},
"status9" : {"label" : "1"},
})
};
var response = UrlFetchApp.fetch("https://api.monday.com/v2", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Authorization': API_KEY,
'API-Version' : '2023-04'
},
payload: JSON.stringify({
'query': query,
'variables': JSON.stringify(vars)
})
})
However, expanding to include a link fails::
This fails with status code 200, invalid value:
let vars = {
"myItemName": "Hello, Best Deal!",
"columnVals": JSON.stringify({
"link": { "link": "https://www.google.com", "text" : "google"},
"deal_stage" : {"label" : "New"},
"status9" : {"label" : "1"},
})
};
and this fails silently (successfully creates item with without the link:
let vars = {
"myItemName": "Hello, Best Deal!",
"columnVals": JSON.stringify({
"link": { "link": "https://www.google.com"},
"deal_stage" : {"label" : "New"},
"status9" : {"label" : "1"},
})
};
Trying to include a people column also fails with status code 200, “Link to item column value structure invalid”:
"deal_contact" : {"people" : {"personsAndTeams" : [ {"id" : "5936051010", "kind" : "person"} ] } }