title: Getting error ()when adding users to google group by google script
body: <p>i am getting error in AdminDirectory.Members.insert(member, groupEmail);</p>
  <p><strong>Failed with error API call to directory.members.insert failed with error: Resource Not Found: groupKey</strong></p>
  <p>not able to add users to google group</p>
  <p>please help!</p>
  <pre><code>function myFunction() {  
    addMembersFromSheet();
  }
  function addMembersFromSheet() {
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;groups&quot;);
  
    // var emails = sheet.getRange(1,1,sheet.getLastRow()-1,1).getValues();
    var emails = SpreadsheetApp.getActive().getRange(&quot;Sheet1!A1:A3&quot;).getValues();
    var group = GroupsApp.getGroupByEmail(&quot;testingw@googlegroups.com&quot;);
  for(i = 0; i &lt; emails.length; i++) {
      try {
        addGroupMember(emails[i][0], 'testingw@googlegroups.com');
        console.log(emails[i][0]);
      }
      catch(e) {
        console.error(e);
        continue;
      }   
    }
  }
  function addGroupMember(userEmail,groupEmail) {  
    const member = {
      email: userEmail,
      role: 'MEMBER'
    };
    try {
      AdminDirectory.Members.insert(member, groupEmail);
  
      Logger.log('User %s added as a member of group %s.', userEmail, groupEmail);
    } catch (err) {
      // TODO (developer)- Handle exception from the API
      Logger.log('Failed with error %s', err.message);
    }
  }
  
  
  </code></pre>