0

Get Folder

by
Published today

Get a mail folder by id or well-known name (`inbox`, `drafts`, `sentitems`, `deleteditems`, `archive`, `junkemail`), with its unread and total counts. Requires Mail.Read (covered by the default Mail.ReadWrite) (a shared mailbox needs Mail.Read.Shared, not a default).

Script ms_outlook Verified

The script

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

3
/**
4
 * Get Folder
5
 * Get a mail folder by id or well-known name (`inbox`, `drafts`, `sentitems`, `deleteditems`, `archive`, `junkemail`), with its unread and total counts. Requires Mail.Read (covered by the default Mail.ReadWrite) (a shared mailbox needs Mail.Read.Shared, not a default).
6
 */
7
export async function main(
8
  auth: RT.MsOutlook,
9
  folder: string,
10
  mailbox: string | undefined
11
) {
12
  const base = `https://graph.microsoft.com/v1.0/${
13
    mailbox != null && mailbox !== ""
14
      ? `users/${encodeURIComponent(mailbox)}`
15
      : "me"
16
  }`
17
  const response = await fetch(
18
    `${base}/mailFolders/${encodeURIComponent(folder)}`,
19
    {
20
      headers: {
21
        Authorization: `Bearer ${auth.token}`,
22
        Accept: "application/json",
23
      },
24
    }
25
  )
26

27
  if (!response.ok) {
28
    throw new Error(`${response.status} ${await response.text()}`)
29
  }
30

31
  return await response.json()
32
}
33