Google Drive API - Adding new users to Shared Drive

Viewed 222

I am using a Google App Script to automate the creation of some Google Accounts inside our of our domain. I have been having a little trouble with some of the API calls and such, however this question is more related to whether or not the Drive API gives me the ability to do something. I have code below that adds editor permissions to the new user for their needed Shared Drives, however I would like to give them 'Content Manager' access to the Shared Drive. From the documentation I have looked at it, it does not seem like this is possible using the Google Drive API however I wanted to ask here to make sure I am not missing something when proceeding with the rest of my automation.

switch(ssValues[i][9]){
    case "Accounting":
      AdminDirectory.Members.insert(groupMember, "notourcompany");
      DriveApp.getFolderById("TH1SDR!v3").addEditor(email);
      break;

Does not matter if I need to use a different method or another API to achieve this functionality, I just want to know if it is possible to do this using their API's or SDK's through an App Scripts project.

Documentation:

  1. Folder Class-https://developers.google.com/apps-script/reference/drive/folder
  2. Drive API - Drives - https://developers.google.com/drive/api/v3/reference/drives
  3. Drive API - Permissions - https://developers.google.com/drive/api/v3/reference/permissions
1 Answers

It should be possible to manage users over a Shared Drive utilizing the Drive API. The important thing is that you would need to give access over the API and make sure the parameter or argument for supportsAllDrives is set to true.

There is a sample Java code over the official documentation that shows how you can add permissions to a Shared Drive that is "orphaned" or you can test it over it in the permission.create documentation:

enter image description here

You can test it yourself over here.

As you can see in the image, the function is very similar to the code that was created on an old thread utilizing the Drive API V2, however it is using the argument supportsTeamDrive. Sample code that could be edited:

Edit:

I have updated the code based on the one suggested from the thread to a more simplify version.

// Using Apps Script with Advance Google Services v2 of the Drive API enable
function insertPermission() {
  const sharedid= 'sharedDriveID' //ID of the Shared Drive
  var resource = {
    // enter email address here
    value: 'emailtest@domain.com', 
    type: 'user',                
    // choose from: "owner" or "fileOrganizer". File Organizer would basically be the contentManager of a SharedDrive. 
    role: 'fileOrganizer'               
  };
  
  var optionalArgs = {
    sendNotificationEmails: false,
    supportsAllDrives: true
  };
  
  Drive.Permissions.insert(resource, sharedid, optionalArgs);
  
}

You can review the thread and code here.

References

Related