0

List Channel Accounts

by
Published today

List channel accounts (a connected mailbox, a chatflow, ...), optionally for one channel or inbox.

Script hubspot Verified

The script

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

3
/**
4
 * List Channel Accounts
5
 * List channel accounts (a connected mailbox, a chatflow, ...), optionally for one channel or inbox. Their IDs are what Send Message expects as `channel_account_id`. Requires conversations.read.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  channel_id: string | undefined,
10
  inbox_id: string | undefined,
11
  limit: number | undefined,
12
  after: string | undefined
13
) {
14
  const url = new URL(
15
    `https://api.hubapi.com/conversations/v3/conversations/channel-accounts`
16
  )
17
  if (channel_id != null && channel_id !== "")
18
    url.searchParams.append("channelId", channel_id)
19
  if (inbox_id != null && inbox_id !== "")
20
    url.searchParams.append("inboxId", inbox_id)
21
  if (limit != null) url.searchParams.append("limit", String(limit))
22
  if (after != null && after !== "") url.searchParams.append("after", after)
23

24
  const response = await fetch(url, {
25
    headers: {
26
      Authorization: `Bearer ${auth.token}`,
27
      Accept: "application/json",
28
    },
29
  })
30

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

35
  return await response.json()
36
}
37