title: Accessing Files and Folders in Team Drive
body: <p>I'm using Google Apps Script and V2 of the Drive API (I don't think V3 is available in scripts yet) to automate file creation inside of a Team Drive. I'd like to add editors with the script with no success.</p>
  
  <p>I can access the Team Drive and child folders using the <code>FolderIterator</code> in the standard <code>DriveApp</code> methods. </p>
  
  <p><strong>Attempt 1</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>function addUserToTeam(email, folders) {
  
    // Open the team drive and get all the folders
    var teamFolders = DriveApp.getFolderById('TEAMDRIVEIDSTRING').getFolders();
  
    var folders = ["folderIdToMatch"]  // This may hold multiple folders
  
    try {
    // Loop an array of folder IDs
      for(var i=0; i&lt;folders.length; i++) {
  
        // Check the team drive folders for a matching name
        while(teamFolders.hasNext()) {
          var teamFolder = teamFolders.next();
          if(folders[i] == teamFolder.getId()) {
            teamFolder.addEditor(email);
          }
        }
      }
    } catch(e) {
      Logger.log(e);
    }
  }
  </code></pre>
  
  <p>This failed with <code>Exception: Cannot use this operation on a Team Drive item</code>.</p>
  
  <p><strong>Attempt 2</strong></p>
  
  <p>I tried the Drive API by substituting <code>teamFolder.addEditor(email)</code> a <code>Permissions</code> resource:</p>
  
  <pre class="lang-js prettyprint-override"><code>if(folders[i] == teamFolder.getId()) {
    var resource = {
      "type":"user",
      "role":"writer",
      "value": email
    }
    Drive.Permissions.insert(resource, teamFolder.getId());
  }
  </code></pre>
  
  <p>This fails with a <code>File not found</code> error.</p>
  
  <p>I can find the folder (or file) with <code>DriveApp</code> methods. Any attempt at the same with the Drive API fails.</p>
  
  <p>I cannot find any documentation saying Team Drive files are inaccessible with the API. Is there something wrong with my approach?</p>