Reputation: 43
function modifyevent(eventid,cal){
var event = cal.getEventById(eventid);
event.deleteEvent();
}
This is working but not sending an email. Do you have an another way to do it with GOOGLE apps script. I would like to delete the event and send an email to attendees which is gonna delete the event from their calendar even if they are using a calendar such as outlook.
This is how I create the event if it can help:
function createEvent(date,start,end,summary,location,email,calendarId,incrementligne,ss){
var newdatestart = new Date(date.getYear(), date.getMonth(), date.getDate(), start.getHours(), start.getMinutes(), "0", "0");
var newdateend = new Date(date.getYear(), date.getMonth(), date.getDate(), end.getHours(), end.getMinutes(), "0", "0");
var invitelist = email.split(',');
var longueur = invitelist.length;
var event = {
summary:summary,
location: location,
description: '',
start: {dateTime: newdatestart.toISOString()},
end: {dateTime: newdateend.toISOString()},
attendees: [
{email: ''},{email: ''}],
// Red background. Use Calendar.Colors.get() for the full list.
colorId: 11
};
for(var i=0; i < invitelist.length;i++){
event.attendees.push({email: invitelist[i]});
}
Upvotes: 3
Views: 6505
Reputation: 5716
In Script Editor, go to 'View' - 'Show manifest file'. In 'appscript.json', add the following scopes:
"oauthScopes": ["https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/script.external_request"]
Go to 'Resources -> 'Cloud Platform Project'. Click on your project name to open project page on GCP. Type 'Calendar API' in the search box at the top of the page. Click "Enable" on the Calendar API page.
Finally, use UrlFetchApp to call the Calendar API endpoint. One thing to note is that you need to modify the string returned by CalendarEvent.getId() to get the actual identifier without the '@google.com' part. I've tested the code below - everything works perfectly, including notifications.
function deleteEvent(eventId) {
var baseUrl = "https://www.googleapis.com/calendar/v3/calendars/{calendarId}/events/{eventId}?sendNotifications=true";
var calendarId = CalendarApp.getDefaultCalendar().getId();
eventId = eventId.substr(0, eventId.indexOf("@"));
var url = baseUrl.replace("{calendarId}", calendarId).replace("{eventId}", eventId);
var options = {
"method": "DELETE",
"headers": {"Authorization":"Bearer " + ScriptApp.getOAuthToken()},
"muteHttpExceptions": true
};
var res = UrlFetchApp.fetch(url, options).getContentText();
Logger.log(res);
}
Upvotes: 3
Reputation: 2014
You can use the GmailApp.sendEmail(String,String,String) method (or MailApp.sendEmail(String,String,String) method, depending of your needs), like:
function modifyevent(eventid,cal){
var event = cal.getEventById(eventid);
var name = event.getTitle();
event.deleteEvent();
GmailApp.sendEmail("[email protected]", "Event deleted", "The event " + name + " has been deleted on " + now.toString());
}
Upvotes: 2