CalendarApp Event ID

Viewed 1088

Using Google Apps Script, I am trying to create an Event in CalendarApp and store a Link to the event in a spreadsheet.

To create a link to the event I need to get the event ID, however using event.getID() in Google Apps Script returns the incorrect event ID.

Format for the link should be:

https://calendar.google.com/calendar/event?eid={eventID}=%7BAmerica/Chicago%7D

Event ID should look something like:

tmFmbHZydmU1aDBDZGhlYmMwaWdqcW1wZGMgdDY1HT6yhuHI5YXJwYW5lMHV2OTYzamtAZw

getID() is returning this:

065cvve58nriutnkuses332fkf@google.com

var event = CalendarApp.getCalendarById(calID).createAllDayEvent(eventName, new Date (eventDate));
var eventID = event.getId();
var eventLink = "https://www.google.com/calendar/event?eid=" + eventID + "&ctz={America/Chicago}";
Logger.log(eventLink);

Why is GAS returning the ID in this format?

3 Answers

The id that is being returned to you is a calendar ID (065cvve58nriutnkuses332fkf@google.com)

If you double check that this matches the id for the calendar you want to create events in - go to settings and sharing for the calendar as shown in the screenshot.

Then you can use this id to call the calendar you want to work with:

calendar = CalendarApp.getCalendarById('065cvve58nriutnkuses332fkf@google.com');

then you can follow up with your original intent...

eventId = calendar.createAllDayEvent(eventName, new Date (eventDate)).getId;

The ID that is returned is an iCalUID and is not interchangeable with the event ID used for specific events. See a related answer on StackExchange by "luc".

The iCalUID ID is used when handling events in multiple calendar systems. For using IDs only within Google Calendar, use luc's recommended method to obtain the event ID via the advanced Calendar services by listing out all events and matching against the iCalUID.

For testing purposes, you can get the event ID by navigating to Google Calendar, clicking on the event, clicking edit, and then copying the part of the URL after "https://calendar.google.com/calendar/r/eventedit/".

Related