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

94
Views
How do you leave a googlegroup via the Googlescript API

What I am trying to do is leave a googlegroup by utilizing the API rather then having to click on the group itself. This is not shown in the API documentation located here: Google Groups API

In trying to find a way to leave a group via the API I did find out I was a member of different groups that I did not join but it appears there is no documented way of leaving them. Going here: Enum Role. This allows me to see what role I have within a group and the corresponding code used is below.

There is a Enterprise Admin API for removing a group membership but this is not a Enterprise setup and thus AdminGroupSettings cannot be used in this scope.

function getGroupNames() {

  try {
      var groups = GroupsApp.getGroups();
  }
  catch(err) {
      console.log("Permission error [getGroup]: Cannot access group members list!");
  }
  
  for (var i = 0; i < groups.length; i++) {
    var group = groups[i];
    var currentUser = Session.getActiveUser();
    // https://stackoverflow.com/questions/62801809/in-google-app-scripts-how-can-you-get-the-group-name-with-the-group-email
    // Groups Settings API/AdminGroupSettings
    // var groupName = AdminGroupsSettings.Groups.get('unsubscribe-me500@arefilled.site').name;
    // console.log("Attempting to get group name: " + groupName + " from address " + groups[i]);
    if (group.getRole(currentUser.getEmail()) == GroupsApp.Role.MEMBER){
        // How to leave group??
        console.log('You are a member of ' + group.getEmail()); 
        continue;
    }
    if (group.getRole(group.getEmail()) == GroupsApp.Role.INVITED){
        // leave group
        console.log('You are invited to ' + group.getEmail());
        continue;
    }
    if (group.getRole(group.getEmail()) == GroupsApp.Role.MANAGER){
        console.log('You are manager of ' + group.getEmail());
        continue;
    }
    if (group.getRole(group.getEmail()) == GroupsApp.Role.OWNER){
        // leave group
        console.log('You are owner of ' + group.getEmail());
        continue;
    }    
      if (group.getRole(group.getEmail()) == GroupsApp.Role.PENDING){
        // leave group
        console.log('You are pending to ' + group.getEmail());
        continue;
    }
  }

}

Is it possible to leave a group via Google Groups API? If so, how?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Answer:

You need to use the Admin SDK Directory API to remove a member from a group.

More Infomation:

The Directory API has a members.delete method which allows you to remove a member from a Google Group.

In Apps Script, you will need to add the AdminDirectory Advanced service to the project, and specify the groupKey of the group and the membersKey of the member you wish to remove in the request:

const groupKey = "XXXXXXXXX"
const memberKey = "YYYYYY"

AdminDirectory.Members.remove(groupKey, memberKey)

A successful deletion will result in an HTTP 204 reponse.

NB: You need to run this code as a domain Admin. It is not possible to remove a member from a Google Group via the API without using the Admin SDK.

about 4 years ago · Juan Pablo Isaza Report
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!