0

Create Side Conversation

by
Published today

Start a side conversation on a ticket (requires the Collaboration add-on, included in Suite Professional and up). `to` is a list of participants of one kind: `{ "email": "[email protected]", "name": "Person" }` for email, `{ "user_id": 123 }` for an agent, `{ "support_group_id": 123, "support_agent_id": 456 }` for a child ticket, `{ "slack_workspace_id": "T123", "slack_channel_id": "C456" }` for Slack, `{ "msteams_channel_id": "19:..." }` for Microsoft Teams.

Script zendesk Verified

The script

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

3
/**
4
 * Create Side Conversation
5
 * Start a side conversation on a ticket (requires the Collaboration add-on, included in Suite Professional and up). `to` is a list of participants of one kind: `{ "email": "person@example.com", "name": "Person" }` for email, `{ "user_id": 123 }` for an agent, `{ "support_group_id": 123, "support_agent_id": 456 }` for a child ticket, `{ "slack_workspace_id": "T123", "slack_channel_id": "C456" }` for Slack, `{ "msteams_channel_id": "19:..." }` for Microsoft Teams.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  subject: string,
11
  body: string,
12
  to: { [key: string]: any }[]
13
) {
14
  const response = await fetch(
15
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations`,
16
    {
17
      method: "POST",
18
      headers: {
19
        Authorization: auth.token
20
          ? `Bearer ${auth.token}`
21
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
22
        "Content-Type": "application/json",
23
        Accept: "application/json",
24
      },
25
      body: JSON.stringify({ message: { subject, body, to } }),
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