1

I have taken the script from this post Which works perfectly when exporting to a folder in "My Drive" but if I try exporting it to folder in a "Shared drive" I get this error:

GoogleJsonResponseException: API call to drive.files.insert failed with error: File not found: 1ENj9R......

Is there any way around this?

Tanaike
  • 181,128
  • 11
  • 97
  • 165
Jon Bowles
  • 119
  • 6

1 Answers1

1

In your situation, please include supportsAllDrives to the query parameter. When the script in this thread is modified, it becomes as follows.

From:

 var resource = {
title: sheet_Name+".csv",
mimeType: "application/vnd.csv"
parents: [{ id: folder_id }]
   }
 var fileJson = Drive.Files.insert(resource,result)

To:

var folderId = "###"; // Please set the folder ID of your shared Drive.
var resource = {
  title: sheet_Name + ".csv",
  mimeType: MimeType.CSV,
  parents: [{id: folderId}]
}
var fileJson = Drive.Files.insert(resource, result, {supportsAllDrives: true});

Note:

  • In this modified script, it supposes that you have the permission for writing the file in the shared Drive. Please be careful this.

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165