0

Reply to Side Conversation

by
Published today

Reply to a ticket's side conversation. `to` takes the same participant objects as Create Side Conversation, e.g. `[{ "email": "[email protected]" }]`.

Script zendesk Verified

The script

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

3
/**
4
 * Reply to Side Conversation
5
 * Reply to a ticket's side conversation. `to` takes the same participant objects as Create Side Conversation, e.g. `[{ "email": "person@example.com" }]`.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  side_conversation_id: string,
11
  body: string,
12
  to: { [key: string]: any }[],
13
  subject: string | undefined
14
) {
15
  const response = await fetch(
16
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations/${side_conversation_id}/reply`,
17
    {
18
      method: "POST",
19
      headers: {
20
        Authorization: auth.token
21
          ? `Bearer ${auth.token}`
22
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
23
        "Content-Type": "application/json",
24
        Accept: "application/json",
25
      },
26
      body: JSON.stringify({
27
        message: { subject: subject || undefined, body, to },
28
      }),
29
    }
30
  )
31

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

36
  return await response.json()
37
}
38