Home > other >  Get file permissions list in Google Shared Drive with Apps Script
Get file permissions list in Google Shared Drive with Apps Script

Time:10-28

I'm trying to get folder and file permissions which is located in Shared Drive. All I can get is permissions list for root Shared Drive but trying to run below code on any ID of file or folder inside throw error.

How it should be done?


function getPermissions_(driveFileID, sharedDriveSupport){
  var thisDrivePermissions = Drive.Permissions.list(
    driveFileID,
    {
      useDomainAdminAccess: USE_DOMAIN_ADMIN_ACCESS,
      supportsAllDrives: sharedDriveSupport
    } 
  );
  return thisDrivePermissions;
}
GoogleJsonResponseException: API call to drive.permissions.list failed with error: Shared drive not found: xxxxxxxx
GoogleJsonResponseException: API call to drive.permissions.list failed with error: File not found:

Edit:

  1. We are using Google Workspace Business Plus subscription
  2. I am domain superadmin
  3. I have access to this file in Shared drive but I expect to have access to every file as an domain admin.
  4. Right now I'm calling this script from web IDE of Apps Script so it is working in my grant scope.
  5. I am the script owner
  6. Script is on my drive

CodePudding user response:

As superadminin you don't have access to all files by default through Google Drive user interface / Google Apps Script. In order to get access to all files in your domain throught Apps Script you have to make use of domain-wide deletegation of authority.

The "not found" errors might occur because the file or shared drive ids are wrong or you don't have access, do double check that the ids are correct and that you passing the parameters correctly. For this you could use Logger.log / console.log to print the variable values to the execution log or use the Apps Script debugger.

Related

  • enter image description here

    Note that this works because you mentioned you have access to the shared drive, however as Rubén mentioned in his answer Google Workspace admins do not have access to all the files, just to the ones that are shared with them, and if you want to have access you can do it using domain wide delegation and user impersonation.

    References:

  • Related