title: Delete user in Google Apps Script - Fix "Resource Not Found userKey" error
body: <p>I am creating a google apps script add-on that will allow us to add and delete users to our google apps domain. Certain information is entered into a google sheet (First name, last name, employee number, etc. etc.). Then, the person entering the users can select all the rows of users they would like to add. </p>
  
  <p>Google apps script then creates a username and password based on their first and last name and enters them to our Google Apps domain among other things. This part works perfectly.</p>
  
  <p>I am trying to write another function that will allow the person managing users to select the rows of users they would like to remove from our domain for whatever reason and click a "Delete Users" button. This will delete the users based on their email address in our system. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>function delUsers() {
  
    var sheet = SpreadsheetApp.getActiveSheet();
    var range = sheet.getActiveRange();
    var i = range.getRow();
    var stop = range.getLastRow();
  
    while (i != stop + 1) {
      var email = sheet.getRange("C" + i).getValue();
      var user = String(email);
      AdminDirectory.Users.remove(user);
    }
  };
  </code></pre>
  
  <p>You will see that the function loops through each row selected and gets the email address. It is in the format "First.Last@domain.com".</p>
  
  <p>The problem is I keep getting the error "Resource Not Found userKey". Per suggestion from AbrahamB below, I made sure my userKey was a string as found in the GAS documentation. I used javascript's <code>typeof</code> to make sure of this.</p>
  
  <p>The weird thing is upon further investigation, the user <em>is</em> actually being deleted, but the "Resource Not Found userKey" error is still being thrown.</p>
  
  <p>Any help in explaining why this error is happening and how to fix it would be appreciated.</p>