Reputation: 33
I currently have a script that takes an email address and role from a Google Spreadsheet and adds them to a Google Apps Admin Group, using the Google Admin SDK from this website. However, I'm looking for a similar script that works to delete users from a list, coming from a spreadsheet. There is an API from Google here, however, I'm not sure how to implement it from the spreadsheet with a Google Script. How can I do this? Any help is appreciated!
Here is what I have now for adding a user from a spreadsheet:
function addGroupMember() {
var userEmail = getUser();
var groupEmail = getGroup();
var member = {
email: userEmail,
role: getRole()
};
member = AdminDirectory.Members.insert(member, groupEmail);
Logger.log('User %s added as a member of group %s.', userEmail, groupEmail);
}
function getUser() {
user = SpreadsheetApp.getActiveSheet().getRange('A2').getValue();
return user }
function getRole() {
role = SpreadsheetApp.getActiveSheet().getRange('B2').getValue();
return role }
Upvotes: 1
Views: 187
Reputation: 1120
Rather than the line member = AdminDirectory.Members.insert(member, groupEmail);
, use:
member = AdminDirectory.Members.remove(groupKey, memberKey);
EDIT: bad copy/paste from my code. Documentation on this is here.
Upvotes: 1
Reputation: 3337
try with this command line:
AdminDirectory.Members.remove(groupKey, memberKey);
where groupeKey is the email adress of the group and memberKey is the email adress of the user
Upvotes: 1