0

Get Side Conversation

by
Published today

Retrieve one of a ticket's side conversations, optionally with its 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
 * Get Side Conversation
5
 * Retrieve one of a ticket's side conversations, optionally with its events (the messages sent and received).
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  side_conversation_id: string,
11
  include_events: boolean
12
) {
13
  const url = new URL(
14
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations/${side_conversation_id}`
15
  )
16
  if (include_events) {
17
    url.searchParams.append("include", "events")
18
  }
19

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

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

33
  return await response.json()
34
}
35