title: Add users to Google Group using Google Apps Script
body: <p>I'm trying to add a user to a Google Group using Google Apps Script.</p>
  
  <p>Here's the code I've tried:</p>
  
  <pre><code>// Adds a user to a Google Group
  function addUsertoGroup(userEmail) {
    var userEmail = 'Name@gmail.com'
    var groupId = "group-name@googlegroups.com";
    var group = GroupsApp.getGroupByEmail(groupId);
  
    // If email is already in group
    try { var hasMember = group.hasUser(userEmail);}
    catch(e){Logger.log(userEmail+" is already in the group"); return}
  
    var newMember = {email: userEmail, role: "MEMBER"};
  
    // This is the line which is throwing an error
    AdminDirectory.Members.insert(newMember, groupId);
  </code></pre>
  
  <p>When running, I receive an error:</p>
  
  <blockquote>
    <p>API call to directory.groups.get failed with error: Domain not found.</p>
  </blockquote>
  
  <p>Any help would be appreciated.</p>