0

List Channels

by
Published today

List the conversation channels (email, chat, forms, ...) of the account.

Script hubspot Verified

The script

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

3
/**
4
 * List Channels
5
 * List the conversation channels (email, chat, forms, ...) of the account. Requires conversations.read.
6
 */
7
export async function main(
8
  auth: RT.Hubspot,
9
  limit: number | undefined,
10
  after: string | undefined
11
) {
12
  const url = new URL(
13
    `https://api.hubapi.com/conversations/v3/conversations/channels`
14
  )
15
  if (limit != null) url.searchParams.append("limit", String(limit))
16
  if (after != null && after !== "") url.searchParams.append("after", after)
17

18
  const response = await fetch(url, {
19
    headers: {
20
      Authorization: `Bearer ${auth.token}`,
21
      Accept: "application/json",
22
    },
23
  })
24

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

29
  return await response.json()
30
}
31