0

List Labels

by
Published today

List the mailbox's system and user labels. Requires gmail.labels, gmail.readonly or gmail.modify on the connection.

Script gmail Verified

The script

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

3
/**
4
 * List Labels
5
 * List the mailbox's system labels (INBOX, UNREAD, ...) and user labels with their ids. Requires gmail.labels, gmail.readonly or gmail.modify on the connection.
6
 */
7
export async function main(auth: RT.Gmail) {
8
  const response = await fetch(
9
    "https://gmail.googleapis.com/gmail/v1/users/me/labels",
10
    {
11
      headers: {
12
        Authorization: `Bearer ${auth.token}`,
13
        Accept: "application/json",
14
      },
15
    }
16
  )
17
  if (!response.ok) {
18
    throw new Error(`${response.status} ${await response.text()}`)
19
  }
20

21
  return await response.json()
22
}
23