1
Update Event
One script reply has been approved by the moderators Verified
Created by rossmccrann 612 days ago Viewed 2542 times
0
Submitted by rossmccrann Deno
Verified 612 days ago
1
type Gcal = {
2
  token: string;
3
};
4
export async function main(
5
  gcal_auth: Gcal,
6
  calendarId: string,
7
  eventId: string,
8
  start_date?: string,
9
  end_date?: string,
10
  description?: string,
11
  summary: string,
12
  location?: string,
13
  attendees?: Array<object>,
14
) {
15
  const alwaysIncludeEmail = true;
16
  const sendUpdates = "all";
17
  const supportsAttachments = true;
18
  const UPDATE_EVENT_URL = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/${eventId}/?alwaysIncludeEmail=${alwaysIncludeEmail}&sendUpdates=${sendUpdates}&supportsAttachments=${supportsAttachments}`;
19

20
  const token = gcal_auth["token"];
21

22
  const body = {
23
    summary: summary,
24
    description: description,
25
    location: location,
26
    end: {
27
      date: end_date,
28
    },
29
    start: {
30
      date: start_date,
31
    },
32
    attendees: attendees,
33
  };
34

35
  const response = await fetch(UPDATE_EVENT_URL, {
36
    method: "PUT",
37
    body: JSON.stringify(body),
38
    headers: {
39
      Authorization: "Bearer " + token,
40
      "Content-Type": "application/json",
41
    },
42
  });
43

44
  const result = await response.json();
45

46
  return result;
47
}
48