Edits history of script submission #23305 for ' Update Event Instance (gcal)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update Event Instance
     * 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.
     */
    export async function main(
      auth: RT.Gcal,
      event_id: string,
      calendar_id: string = "primary",
      summary: string | undefined,
      description: string | undefined,
      location: string | undefined,
      start: string | undefined,
      end: string | undefined,
      time_zone: string | undefined,
      attendees: string[] | undefined,
      send_updates: "all" | "externalOnly" | "none" = "all"
    ) {
      const when = (v: string) =>
        /^\d{4}-\d{2}-\d{2}$/.test(v)
          ? { date: v, dateTime: null }
          : { dateTime: v, date: null, timeZone: time_zone || undefined }
      const body: { [key: string]: any } = {
        summary: summary || undefined,
        description: description || undefined,
        location: location || undefined,
        start: start ? when(start) : undefined,
        end: end ? when(end) : undefined,
        attendees: attendees?.length
          ? attendees.map((email) => ({ email }))
          : undefined,
      }
    
      const response = await fetch(
        `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendar_id || "primary")}/events/${event_id}?sendUpdates=${send_updates || "all"}`,
        {
          method: "PATCH",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify(body),
        }
      )
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 6 hours ago