1

Create Event

by
Published Jul 26, 2022
Script gcal Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 6 days ago
1
//native
2

3
type Gcal = {
4
  token: string;
5
};
6
export async function main(
7
  gcal_auth: Gcal,
8
  calendarId: string,
9
  start_date?: string,
10
  end_date?: string,
11
  description?: string,
12
  summary: string,
13
  location?: string,
14
  attendees?: Array<object>,
15
  maxAttendees?: number = 2,
16
) {
17
  const sendNotifications = true;
18
  const sendUpdates = "all";
19
  const supportsAttachments = true;
20

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

23
  const token = gcal_auth["token"];
24

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

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

47
  const result = await response.json();
48

49
  return result;
50
}
51

Other submissions
  • Submitted by rossmccrann Deno
    Created 398 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