0

List Side Conversations

by
Published today

List a ticket's side conversations, optionally with their events (the messages sent and received).

Script zendesk Verified

The script

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

3
/**
4
 * List Side Conversations
5
 * List a ticket's side conversations, optionally with their events (the messages sent and received).
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  include_events: boolean
11
) {
12
  const url = new URL(
13
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations`
14
  )
15
  if (include_events) {
16
    url.searchParams.append("include", "events")
17
  }
18

19
  const response = await fetch(url, {
20
    headers: {
21
      Authorization: auth.token
22
        ? `Bearer ${auth.token}`
23
        : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
24
      Accept: "application/json",
25
    },
26
  })
27

28
  if (!response.ok) {
29
    throw new Error(`${response.status} ${await response.text()}`)
30
  }
31

32
  return await response.json()
33
}
34