1 | |
2 |
|
3 | |
4 | * List Threads |
5 | * List conversation threads, optionally for one inbox or one contact. `associated_contact_id` cannot be combined with `inbox_id`. Requires conversations.read. |
6 | */ |
7 | export async function main( |
8 | auth: RT.Hubspot, |
9 | inbox_id: string | undefined, |
10 | associated_contact_id: string | undefined, |
11 | thread_status: "OPEN" | "CLOSED" | undefined, |
12 | sort: string | undefined, |
13 | limit: number | undefined, |
14 | after: string | undefined, |
15 | archived: boolean | undefined |
16 | ) { |
17 | const url = new URL( |
18 | `https://api.hubapi.com/conversations/v3/conversations/threads` |
19 | ) |
20 | if (inbox_id != null && inbox_id !== "") |
21 | url.searchParams.append("inboxId", inbox_id) |
22 | if (associated_contact_id != null && associated_contact_id !== "") |
23 | url.searchParams.append("associatedContactId", associated_contact_id) |
24 | if (thread_status != null && thread_status !== "") |
25 | url.searchParams.append("threadStatus", thread_status) |
26 | if (sort != null && sort !== "") url.searchParams.append("sort", sort) |
27 | if (limit != null) url.searchParams.append("limit", String(limit)) |
28 | if (after != null && after !== "") url.searchParams.append("after", after) |
29 | if (archived) url.searchParams.append("archived", String(archived)) |
30 |
|
31 | const response = await fetch(url, { |
32 | headers: { |
33 | Authorization: `Bearer ${auth.token}`, |
34 | Accept: "application/json", |
35 | }, |
36 | }) |
37 |
|
38 | if (!response.ok) { |
39 | throw new Error(`${response.status} ${await response.text()}`) |
40 | } |
41 |
|
42 | return await response.json() |
43 | } |
44 |
|