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?