Drive.Files.insert fail

1,406 views
Skip to first unread message

DWoodard

unread,
Apr 28, 2022, 5:23:52 PM4/28/22
to Google Apps Script Community
Hi All - I am utilizing script found in another post on another site because I am brand new to this....
I am looking to insert data from all csv files in a folder into a "master" google sheet and append the data as new csv's are dropped. I keep getting an error with the Drive.File.Insert API call. From the replies on the site this was originally posted too it seems to have worked but I keep getting an error that the insert fails due to file not found:
"Error
GoogleJsonResponseException: API call to drive.files.insert failed with error: File not found: Folder Name
Script is as follows:
function appendData() {
  var sheet = SpreadsheetApp.getActiveSheet();
  
  var folderId = DriveApp.getFolderById("FolderID");
  var files = folderId.getFiles();
  
  while (files.hasNext()) {
    var tempFile = "";
    var file = files.next();
    // if the file is not a Sheet, skip it
    if (file.getMimeType() != "application/vnd.google-apps.spreadsheet") {
      tempFile = { 
        "title": file.getName(), 
        "parents": [ {
          "id": folderId
        }] 
      }; 

      file = Drive.Files.insert (tempFile, file.getBlob(), {"convert": true, "supportsAllDrives": true });
    }
   Thanks in advance!   

Tanaike

unread,
Apr 29, 2022, 8:40:36 AM4/29/22
to Google Apps Script Community
About "I keep getting an error with the Drive.File.Insert API call.", in your script, `folderId` of `"id": folderId` is `var folderId = DriveApp.getFolderById("FolderID");`. In this case, the Class Folder object is used as the folder ID. So, how about directly putting the folder ID like `"id": "FolderID"`?

DWoodard

unread,
May 2, 2022, 9:08:38 AM5/2/22
to Google Apps Script Community
perfect - thank you for pointing that out!

Tanaike

unread,
May 3, 2022, 3:41:06 AM5/3/22
to Google Apps Script Community
Thank you for replying and testing it. I'm glad your issue was resolved.

Reply all
Reply to author
Forward
0 new messages