Get a whole Gmail conversation by thread ID.
1
//native
2
3
/**
4
* Get Thread
5
* Get a whole Gmail conversation by thread ID (the `threadId` on any message), with every message in order. Use the `metadata` format to skip message bodies on long threads.
6
*/
7
export async function main(
8
auth: RT.Gmail,
9
thread_id: string,
10
format: "full" | "metadata" | "minimal" = "full"
11
) {
12
const url = new URL(
13
`https://gmail.googleapis.com/gmail/v1/users/me/threads/${thread_id}`
14
)
15
url.searchParams.append("format", format)
16
17
const response = await fetch(url, {
18
headers: {
19
Authorization: `Bearer ${auth.token}`,
20
Accept: "application/json",
21
},
22
})
23
if (!response.ok) {
24
throw new Error(`${response.status} ${await response.text()}`)
25
}
26
27
return await response.json()
28
29