1
Create Event
One script reply has been approved by the moderators Verified
Created by rossmccrann 852 days ago Viewed 9437 times
0
Submitted by rossmccrann Deno
Verified 852 days ago
1
type Gcal = {
2
  token: string;
3
};
4
export async function main(
5
  gcal_auth: Gcal,
6
  calendarId: string,
7
  start_date?: string,
8
  end_date?: string,
9
  description?: string,
10
  summary: string,
11
  location?: string,
12
  attendees?: Array<object>,
13
  maxAttendees?: number = 2,
14
) {
15
  const sendNotifications = true;
16
  const sendUpdates = "all";
17
  const supportsAttachments = true;
18

19
  const CREATE_EVENT_URL = `https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/?maxAttendees=${maxAttendees}&sendNotifications=${sendNotifications}&sendUpdates=${sendUpdates}&supportsAttachments${supportsAttachments}`;
20

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

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

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

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

47
  return result;
48
}
49