Advanced Drive Service: Create a sub folder in Shared Drive Folder

494 views
Skip to first unread message

Stephen Hind

unread,
Jun 24, 2022, 10:43:53 AMJun 24
to Google Apps Script Community
Hi

I'm trying to use the advanced Drive service to create a subfolder (or a shortcut for that matter) in a specified parent folder on a Shared Drive but I get this error message:

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

where 1kHZXAB0G29jEMzOG3J05u90FNkMAmscD is the parent folder ID I'm trying to put the subfolder in.

Here's the function: 

function createSubFolder({ parentFolderId = false, subFolderName = false }) {
  if(!parentFolderId) { console.log(`Missing required parameter parentFolderId`); return }
  if(!subFolderName) { console.log(`Missing required parameter subFolderName`); return } 
  return Drive.Files.insert({
    supportsAllDrives: true,
         parents: [{ id: parentFolderId }], 
    title: subFolderName, 
    mimeType: `application/vnd.google-apps.folder` 
  }) 
}

 Any ideas? It must be really simple but I just cannot find what I've done wrong.

Stephen

Tanaike

unread,
Jun 26, 2022, 4:27:26 AMJun 26
to Google Apps Script Community
It seems that the arguments of `Drive.Files.insert` are `resource: Drive_v2.Drive.V2.Schema.File, mediaData: Blob, optionalArgs: Object`. So, when your script is modified, it becomes as follows.

From


return Drive.Files.insert({
  supportsAllDrives: true,
       parents: [{ id: parentFolderId }],
  title: subFolderName,
  mimeType: `application/vnd.google-apps.folder`
})

To

return Drive.Files.insert({

  parents: [{ id: parentFolderId }],
  title: subFolderName,
  mimeType: `application/vnd.google-apps.folder`
}, null, { supportsAllDrives: true });

Stephen Hind

unread,
Jul 5, 2022, 12:08:22 PMJul 5
to Google Apps Script Community
Thanks!  That sorted it!
Reply all
Reply to author
Forward
0 new messages