Parse error on "-"

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’)
}

Could the error be on line 3?

var escapedFullProjectName = xxx-1234

It looks like it lacks the double-quote around the value.
Maybe something like this :

var escapedFullProjectName = "xxx-1234"

Or full-version :

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")
}

Hi @ellis! Thank you for your quick answer. But it seems issue isn’t about quotes. It’s the parsing error for each special symbol in group names:

{“errors”:[{“message”:“Parse error on “-1234” (INT) at [1, 61]”,“locations”:[{“line”:1,“column”:61}]}],“account_id”:myId}

I have the same one in server response. Working on it.

1 Like

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:" + escapedFullProjectName + ") {id} }";

to

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.

Hi @yuhaocooper!

I’ve found the solution for you. You should add another pair of quotes in the name of group:

var escapedFullProjectName = ‘“xxx-1234”’;

And it will work, the server response will be:
{“data”:{“create_group”:{“id”:“xxx_1234”}},“account_id”:my_id}

You can notice that in the response you have “_” symbol. But group will be created on Monday.com with the properly name:

1 Like

Hi @olena ,

It worked! Thanks for your help!

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.

Hey there! Apologies for the delay on this - it is indeed something on the GraphQL side. If I can answer any questions on it please let me know.

-Daniel