Hi,
I have a Google Sheet with file names and Monday pulseIDs. I am trying to write a script to cycle through the files and add them in Monday to the specific pulse. I have use the API many times from Google sheets and it works great. I have not been successful with files though.
I have been trying to use my understanding of the typical structure, then reading posts on Monday community about uploading files and looking at other sources how to do similar things with GAS. I have not had luck yet.
Here is what I have so far, it just returns an unsupported query erro:
function testFile(){
var fileName = “Copy of Workspace files metadata (backup) - backup.pdf”;
var url = “https://api.monday.com/v2/file”;
var file = DriveApp.getFilesByName(fileName).next();
var boundary = “xxxxxxxxxx”;
var data = “”;
data += “–” + boundary + “\\r\\n”;
data += “Content-Disposition: form-data; name="file"; filename="” + file.getName() + “"\\r\\n”;
data += “Content-Type:” + file.getMimeType() + “\\r\\n\\r\\n”;
var nfile = Utilities.newBlob(data).getBytes()
.concat(file.getBlob().getBytes())
.concat(Utilities.newBlob(“\\r\\n–” + boundary + “–”).getBytes());
var query = ‘mutation($file:File!,$item:Int!){add_file_to_column(file:$file,item_id:$item,column_id:“files”){id}}’
var variables = {
“file”: nfile,
“item”: 839038968
}
var options = {
“method” : “post”,
“headers” : {
“Authorization” : mondayAPIkey,
},
“contentType” : “multipart/form-data; boundary=” + boundary,
“payload” : JSON.stringify({
“query” : query,
“variables” : variables,
}),
“muteHttpExceptions”: true,
};
var res = UrlFetchApp.fetch(url, options).getContentText();
Logger.log(res);
}