Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Google Calendar Event Free/Busy with Calendar API

I have a GAS web app for reserving rooms. When the app creates the event, it currently defaults to "Busy" for the event. I am trying to set the default to "Free".

I found a GAS forum entry that recommends using the Advanced Google Calendar API to edit the transparency field (Source: https://code.google.com/p/google-apps-script-issues/issues/detail?id=2341).

The script they suggested was

var changes = {
transparency: "transparent"
};
Calendar.Events.patch(changes, cal_id, event_id);

I have the Advanced API enabled, but for some reason I am getting an uncaught error prompt in the Chrome console when the function executes. Any thoughts on where this error is coming from?

like image 601
DLee Avatar asked Aug 31 '25 05:08

DLee


1 Answers

After looking around, the following seems to work. I forgot that you need to remove the "@google.com" from the event ID returned by CalendarApp before making a request to CalendarApi. The calendarId can be set to 'primary' since the user is only editing an event on their own calendar

var eventId= event_id.slice(0,event_id.length-11);
var calendarId = 'primary';
Logger.log(eventId)
var changes = {
    transparency: "transparent"
  };
Calendar.Events.patch(changes,calendarId,eventId);
like image 123
DLee Avatar answered Sep 02 '25 19:09

DLee