0

Update Side Conversation

by
Published today

Close or reopen a ticket's side conversation, and/or change its subject. Only the fields you fill are changed.

Script zendesk Verified

The script

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

3
/**
4
 * Update Side Conversation
5
 * Close or reopen a ticket's side conversation, and/or change its subject. Only the fields you fill are changed.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  side_conversation_id: string,
11
  state: "open" | "closed" | undefined,
12
  subject: string | undefined
13
) {
14
  if (!state && !subject) {
15
    throw new Error("Provide a state, a subject, or both")
16
  }
17

18
  const response = await fetch(
19
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations/${side_conversation_id}`,
20
    {
21
      method: "PUT",
22
      headers: {
23
        Authorization: auth.token
24
          ? `Bearer ${auth.token}`
25
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
26
        "Content-Type": "application/json",
27
        Accept: "application/json",
28
      },
29
      body: JSON.stringify({
30
        side_conversation: {
31
          state: state || undefined,
32
          subject: subject || undefined,
33
        },
34
      }),
35
    }
36
  )
37

38
  if (!response.ok) {
39
    throw new Error(`${response.status} ${await response.text()}`)
40
  }
41

42
  return await response.json()
43
}
44