0

Update Event Instance

by
Published today

Change one occurrence of a recurring event (or any single event); only the fields you set are changed.

Script gcal Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 hours ago
1
//native
2

3
/**
4
 * Update Event Instance
5
 * Change one occurrence of a recurring event without touching the rest of the series (get instance ids from List Event Instances). Works on any event id; only the fields you set change. `start`/`end` take `YYYY-MM-DD` for all-day or RFC 3339 (`2026-10-05T10:00:00+02:00`); `time_zone` (IANA, e.g. Europe/Paris) applies to both. `attendees` replaces the guest list.
6
 */
7
export async function main(
8
  auth: RT.Gcal,
9
  event_id: string,
10
  calendar_id: string = "primary",
11
  summary: string | undefined,
12
  description: string | undefined,
13
  location: string | undefined,
14
  start: string | undefined,
15
  end: string | undefined,
16
  time_zone: string | undefined,
17
  attendees: string[] | undefined,
18
  send_updates: "all" | "externalOnly" | "none" = "all"
19
) {
20
  const when = (v: string) =>
21
    /^\d{4}-\d{2}-\d{2}$/.test(v)
22
      ? { date: v, dateTime: null }
23
      : { dateTime: v, date: null, timeZone: time_zone || undefined }
24
  const body: { [key: string]: any } = {
25
    summary: summary || undefined,
26
    description: description || undefined,
27
    location: location || undefined,
28
    start: start ? when(start) : undefined,
29
    end: end ? when(end) : undefined,
30
    attendees: attendees?.length
31
      ? attendees.map((email) => ({ email }))
32
      : undefined,
33
  }
34

35
  const response = await fetch(
36
    `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendar_id || "primary")}/events/${event_id}?sendUpdates=${send_updates || "all"}`,
37
    {
38
      method: "PATCH",
39
      headers: {
40
        Authorization: `Bearer ${auth.token}`,
41
        "Content-Type": "application/json",
42
        Accept: "application/json",
43
      },
44
      body: JSON.stringify(body),
45
    }
46
  )
47
  if (!response.ok) {
48
    throw new Error(`${response.status} ${await response.text()}`)
49
  }
50

51
  return await response.json()
52
}
53