0

Respond to Event

by
Published today

Accept, tentatively accept or decline a meeting invitation you received, optionally with a comment sent to the organizer. The comment is only sent when `send_response` is on, and the organizer cannot respond to their own meeting. Requires Calendars.ReadWrite (a connection default).

Script ms_outlook Verified

The script

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

3
/**
4
 * Respond to Event
5
 * Accept, tentatively accept or decline a meeting invitation you received, optionally with a comment sent to the organizer. The comment is only sent when `send_response` is on, and the organizer cannot respond to their own meeting. Requires Calendars.ReadWrite (a connection default).
6
 */
7
export async function main(
8
  auth: RT.MsOutlook,
9
  event_id: string,
10
  response_type: "accept" | "tentativelyAccept" | "decline",
11
  comment: string | undefined,
12
  send_response: boolean = true
13
) {
14
  const body: { [key: string]: any } = { sendResponse: send_response }
15
  // Graph rejects a comment when no response is sent
16
  if (send_response && comment != null && comment !== "") body.comment = comment
17

18
  const response = await fetch(
19
    `https://graph.microsoft.com/v1.0/me/events/${encodeURIComponent(
20
      event_id
21
    )}/${response_type}`,
22
    {
23
      method: "POST",
24
      headers: {
25
        Authorization: `Bearer ${auth.token}`,
26
        "Content-Type": "application/json",
27
        Accept: "application/json",
28
      },
29
      body: JSON.stringify(body),
30
    }
31
  )
32

33
  if (!response.ok) {
34
    throw new Error(`${response.status} ${await response.text()}`)
35
  }
36

37
  // 202 Accepted with an empty body
38
  return { success: true }
39
}
40