Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
Getting error ()when adding users to google group by google script

i am getting error in AdminDirectory.Members.insert(member, groupEmail);

Failed with error API call to directory.members.insert failed with error: Resource Not Found: groupKey

not able to add users to google group

please help!

function myFunction() {  
  addMembersFromSheet();
}
function addMembersFromSheet() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("groups");

  // var emails = sheet.getRange(1,1,sheet.getLastRow()-1,1).getValues();
  var emails = SpreadsheetApp.getActive().getRange("Sheet1!A1:A3").getValues();
  var group = GroupsApp.getGroupByEmail("testingw@googlegroups.com");
for(i = 0; i < 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);
  }
}


about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!