Google Calendar API makes it easy to tell if an "attendee" is actually a resource:
https://developers.google.com/google-apps/calendar/v3/reference/events#resource
However, how can I tell if an "attendee" is actually a group, as opposed to a single person. ie. [email protected] vs [email protected]
As of December 2019, this is still not possible with the Google Calendar API, but it is possible if you are a G Suite domain administrator and have access to the G Suite Admin SDK Directory API.
Here's an example function which uses the Admin SDK Directory Service in Google Apps Script.
You send an email address string to getGSuiteAddressType()
and it returns an object with the address type from the following:
user
userAlias
group
groupAlias
null
(if that address was not found in the G Suite domain)And it also has the following extra features which may be convenient for G Suite developers:
This uses Google Apps Script but the API can be accessed using any of the languages listed in the Quickstarts sidebar section of this page.
function getGSuiteAddressTypeTest() {
getGSuiteAddressType('[email protected]'); // returns addressType "group"
getGSuiteAddressType('[email protected]'); // returns addressType "groupAlias"
}
function getGSuiteAddressType(email) {
email = email.toLowerCase();
var data = {
email: email,
addressType: null,
aliasOf: null,
lastLoginTime: null
};
// check user and aliases
try {
var user = AdminDirectory.Users.get(email);
data.addressType = 'user';
for (var i = 0; i < user.aliases.length; i++) {
var alias = user.aliases[i].toLowerCase();
if (email === alias) {
data.addressType = 'userAlias';
data.aliasOf = user.primaryEmail;
}
}
} catch (e) {}
if (data.addressType) {
var lastLoginTimestamp = user.lastLoginTime; // this outputs an ISO 8601 string that can be used to create a new date object
if (lastLoginTimestamp === '1970-01-01T00:00:00.000Z') {
Logger.log('the user has never logged in');
} else {
data.lastLoginTime = new Date(lastLoginTimestamp);
}
return data;
}
try {
var group = AdminDirectory.Groups.get(email);
data.addressType = 'group';
if (group.aliases) {
for (var i = 0; i < group.aliases.length; i++) {
if (email === group.aliases[i].toLowerCase()) {
data.addressType = 'groupAlias';
data.aliasOf = group.email;
}
}
}
data.members = [];
var groupMembers = getMembersOfGroup(email);
for (var i = 0; i < groupMembers.length; i++) {
data.members.push(groupMembers[i].email);
}
} catch (e) {}
return data;
}
function getMembersOfGroup(groupEmail) {
var pageToken, page;
var members = [];
do {
try {
page = AdminDirectory.Members.list(groupEmail, {
pageToken: pageToken
});
if (page.members) {
members = members.concat(page.members);
}
pageToken = page.nextPageToken;
} catch (e) {}
} while (pageToken);
return members;
}
This is currently not possible with Calendar API v3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With