google-calendar-api

Cancelling all Recurring Events past a certain date


I've been attempting to cancel all future recurring events past a certain date, according to this documentation However, when attempting to update the recurrence property with a new UNTIL date, ALL of my recurring events except one (Whether they are before or after the new UNTIL date) are removed.

My event is created with events.insert() using the following payload structure:

{
    calendarId: MY_CALENDAR_ID
    sendUpdates: 'none',
    resource: {
        start: {
            dateTime: <Some dateTime value>
            timeZone: MY_TIMEZONE
        },
        end: {
            dateTime: <Some dateTime value>
            timeZone: MY_TIMEZONE
        },
        recurrence: ['RRULE:FREQ=WEEKLY'],

        // Non key values
        summary: "..."
        attendees: [{ email: email@email.com, responseStatus: 'accepted'}, ...]
        guestsCanInviteOthers: false,
        guestsCanModify: false,
        visibility: 'default',
    }
}

The steps to cancel future recurring instances are: First, events.get() with the payload

{
    eventId: MY_EVENT_ID
    calendarId: MY_CALENDAR_ID
}

Where MY_EVENT_ID is one of the instances of the recurring event.

Then call events.update() with the following payload:

{ 
   calendarId: MY_CALENDAR_ID,
   eventId: retrievedEvent.data.recurringEventId,
   requestBody: { 
       ...retrievedEvent.data, 
       recurrence: ['RRULE:FREQ=WEEKLY;UNTIL=20250619T014535Z']
   }
}

Expected behavior: All recurring instances after the new UNTIL date are cancelled, but those before the date are retained.

Actual behavior: ALL recurring instances are cancelled, regardless of date. The retrievedEvent is converted into a non-recurring regular event

By calling events.list() with the parameter showDeleted: true, I can verify that all of the recurring instances - both before and after the new UNTIL date, still exist but have been changed to "status": "cancelled". Only the retrievedEvent's status is still "confirmed", but it no longer has a recurringEventId, indicating that it is now a regular non-recurring event

Edit: Updated question with more details for clarity


Solution

  • It appears that this is an identified key behavior of the Google Calendar API when updating recurring events with an UNTIL rule. The behavior you're expecting—a simple "trimming" of future occurrences while preserving all past instances and their exceptions—is unfortunately not how the events.update() method currently functions with RRULE:UNTIL.

    Based on a series of tests and observations, when you update an existing recurring event by adding or modifying its RRULE to include an UNTIL parameter using events.update(), the API fundamentally redefines the original recurring series. It doesn't simply "trim" the existing series from a certain point forward while preserving past instances or exceptions.

    Current Behavior of events.update() with RRULE:UNTIL Redefines the entire series: The definition of the original recurring event is essentially overwritten by the events.update() call with a new RRULE (including UNTIL). All instances outside the newly determined recurrence pattern (including the UNTIL date) are eliminated. It includes both past and future instances. This section explains why just the original template instance is left and why you're seeing instances before the new UNTIL date is removed. Changes the original event (from which existingEventData was formed) into a non-recurring event: If the event instance you updated (identified by existingEventData.recurringEventId) is the only one that complies with the new rule or if the recurrence is effectively eliminated for it, the API treats it as the new single instance.

    This behavior is consistent with how the API handles changes to the core recurring event description, even if it would seem confusing to someone expecting a straightforward "trimming" operation.

    Official Google Issue Tracker Reference:

    This particular behavior, along with the need for more precise control over changes to recurring events (such as removing future occurrences while keeping past ones and exceptions), is being discussed and has a feature request/bug report on the Google Issue Tracker, as you've found:

    (Google Issue Tracker: Issue 403934488 - Google Calendar API - Recurring Events: allow to delete future events of a series, while preserving all past events (incl. exceptions)

    You can star this issue on the tracker to indicate your interest and receive updates on its progress.