Get link (url) to an calendar event in google apps script
For given event
object of type CalendarEvent and given calendarId
, the simplest and working way to build an URL to view/edit corresponding event in Google Calendar App is the following:
var splitEventId = event.getId().split('@');
var eventURL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + calendarId);
The best thing is that no Google API invocation, authentication, ... needed!
The new version of Google Calendar has broken this. Here's how to fix it:
var mycal = 'username@m'
var splitEventId = event.getId().split('@');
var eventUrl = "https://www.google.com/calendar/event?eid=" +
Utilities.base64Encode(splitEventId[0] + " " + mycal).toString().replace('=','');
Allright... In 2020 this is the working version of this in case somebody is still struggling with this...
var calendarID = "[email protected]";
var event = CalendarApp.getCalendarById(calendarID).createEvent(/*SOME OPTIONS HERE*/);
var splitEventId = event.getId().split('@');
// Open the "edit event" dialog in Calendar using this URL:
var event_EDIT_URL = "https://calendar.google.com/calendar/r/eventedit/" + Utilities.base64Encode(splitEventId[0] + " " + calendarID).replace("==",'');
// Open the "view this event in a Calendar" using this URL:
var event_VIEW_IN_CAL_URL = "https://www.google.com/calendar/event?eid=" + Utilities.base64Encode(splitEventId[0] + " " + calendarID).replace("==",'');
return event_EDIT_URL; // OR return event_VIEW_IN_CAL_URL;