Hi, I’m building a way to automate the duplicate and creation of group items in my monday board through Google Sheet and Appsscript. However, I’m facing a problem with Parse error on “-”, and I can’t seem to get rid of it even after trying to escape it from my variable. Some help here will be good. I’ve copied the code below with an example of the escapedFullProjectName variable
function overviewGroupCreate(escapedFullProjectName){
//Create Monday board and tasks lists of it
var escapedFullProjectName = xxx-1234
var mutation = ‘mutation{ create_group (board_id:’+overviewId+‘, group_name:’+escapedFullProjectName+‘) {id} }’;
var response = UrlFetchApp.fetch(“https://api.monday.com/v2”, {
method: ‘post’,
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’: apiKey
},
payload: JSON.stringify({
‘query’: mutation
})
})
var json = response.getContentText()
var data = JSON.parse(json)
//cache the createdOverviewId
cache.put(‘createdOverviewId’,data[‘data’][‘create_group’][‘id’],600)
Logger.log(‘Overview Group Created’)
}
Thanks for the responses guys. But yeah, ellis, sorry for missing out the quotation as the variable was added in to make my post a little clearer, and I didn’t copy my original variable which contains it, but that isn’t the problem.
From the error message, it seems to be the “-” special character within the string causing the JSON object to not be parsed properly when sent to monday’s server. For e.g. I can change
var mutation = "mutation{ create_group (board_id:overviewId , group_name:abc-xxx) {id} }";
with “-” as part of the string directly, and it will still cause an error. I’ve tried escaping the “-” using both “” and “” to no avail. Hoping for some solutions and explanation in the community.
Do you have any idea what’s the rationale for this though? Is it a JSON formatting or a monday.com server rendering rule that requires us to wrap special characters such as “-” in additional quotations?
As far as I understood it’s some strange behaviour of GraphQL on server side. It tries to parse the string by itself instead of passing it further. And for prevention this parsing we add one more quotation.
But I can be mistaken.