Apps script mutation request

Hi team,
It seems that I encounter a problem for sending creating items request to Monday API with Apps script.

Here is my Apps script code :
let mutation = mutation {create_item(board_id: 802400041, group_id: "topics", item_name: "${dateString}",column_values: "{\"statut\":{\"index\":2}}"){id}};
let payload = {query: mutation};
let options = {
“headers”: headers,
“method” : ‘POST’,
“payload”: JSON.stringify(payload),
“muteHttpExceptions”: true
};
let response = UrlFetchApp.fetch(mondayUrl, options);

The stringified payload sent to the api :
{“query”:“mutation {create_item(board_id: 802400041, group_id: “topics”, item_name: “13/1/2021 17:29:54”,column_values: “{“statut”:{“index”:2}}”){id}}”}

And the api response:
response : {“errors”:[{“message”:“Parse error on “:{” (STRING) at [1, 117]”,“locations”:[{“line”:1,“column”:117}]}],“account_id”:5740895}

I’ve tried many modifications of the “mutation” variable, but get allways errors.
Any ideas to help me?
Thanks

Hi, the mutation seems to be working on my end, but I think you made a typo? statut did you mean status ?

Also, I think you missed a slash which may have messed some things up.
I recommend taking advantage of JSON.stringify() that way you don’t have to manually figure out where to put slashes and quotes.

mutation {
  create_item(
    board_id: your-board-id,
    item_name: "test", 
    group_id: "topics",
    column_values: "{\"status\": {\"index\": 2}}" ) {
    id
  }
}

Hi All,

Problem solved by following this tutorial : https://support.monday.com/hc/en-us/articles/360013465599-API-Quickstart-Tutorial-Javascript
Thanks

1 Like