Reputation: 13
I am trying to ascertain if it possible to create a new Shared Drive (formerly "Team Drive") using Google Apps Script. I can see plenty examples of creating new folders inside an already-existing team drive, but not creating an entirely new drive.
I am hoping to be able to develop an Apps Script to create new team drives containing a pre-prepared structure of folders and documents, that individual teams can tailor to their own specific needs.
Upvotes: 0
Views: 1516
Reputation: 897
This can be done very straightforwardly using the Drive API method, insert
Drive.Teamdrives.insert({name:"My New Team Drive"}, Math.floor(Math.random() * 1000000000000));
The second number simply has to be unique for each request to prevent multiple requests to make the same resource, and can even be entered manually.
Regarding the replication of a folder structure: There are multiple ways that can be achieved such as "hard-coding" in each folder creation, or something more complex which refers to a ready-made structure and deep-copies it, but I feel the question is answered in principle with the code snippet above.
Upvotes: 3
Reputation: 76579
you would have to use a service-account.json
(for an account, which has oAuth2 scope https://www.googleapis.com/auth/drive
) in order to create a Team Drive through the Drive API. App Script
itself does not feature methods to do that, but one can access just any REST API
with UrlFetchApp. once wrote a client called CloudDatastore.gs, which should provide a good example of how it works, despite it's another API (and I don't intent to write such a drive client, unless being paid).
Upvotes: 0