Google Calendar: Delete Event
Deletes an event on Google Calendar.
Configs: Common
  • Step Name
  • Note
Configs
  • C1: User who connects to Google Calendar *
  • C2: Calendar ID (Primary Calendar if blank)
  • C3: Event ID *
Script (click to open)

main();
function main() {
  //// == 工程コンフィグの参照 / Config Retrieving ==
  const quser = configs.getObject("conf_User");
  if (quser === null) {
    throw `User not found.`;
  }
  let calendarId = configs.get("conf_CalendarId");
  if (calendarId === "" || calendarId === null) {
    calendarId = "primary";
  }
  const eventId = engine.findData(configs.getObject("conf_EventId"));
  if (eventId === "" || eventId === null) {
    throw "Event ID isn't set";
  }

  //// == 演算 / Calculating ==
  if (calendarId.search(/[^\w\.@]/) !== -1) {
    throw "Invalid Calendar ID";
  }
  deleteEvent(quser,calendarId,eventId);
}
/**
 * Google カレンダーの予定を削除する
 * @param {QuserView} quser ユーザー
 * @param {String} calendarId カレンダーID
 * @param {String} eventId 予定ID
 */
function deleteEvent(quser,calendarId,eventId) {
  const uri = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/${eventId}`;

  const response = httpClient.begin()
    .googleOAuth2(quser, "Calendar")
    .delete(uri);

  const status = response.getStatusCode();
  const responseStr = response.getResponseAsString();
  engine.log(`Event ID: ${eventId}`);
  engine.log(`Status: ${status}`);
  if (status >= 300) {
    engine.log(responseStr);
    throw `Failed to delete.`;
  }
  engine.log("Succeeded to delete");
}

Notes

  • Users in C1 need to have a configured connection with Google Calendar in [Account Settings] > [Google Connectivity].
  • Refer to the following page for Calendar ID. [Calendar Settings] > [Calendar Address]
  • Event ID can’t be found in the Calendar Page. You should use one from a task such as Start: Google Calendar: Event Started.

Capture

See also

Appendix

  • google-calendar-event-delete.xml (C) Questetra, Inc. (MIT License)
    • If you are using Professional, you can modify the contents of this file and use it as your own add-on
%d bloggers like this: