0

Merge Tickets into Target Ticket

by
Published Nov 7, 2023

Merges one or more tickets into the ticket with the specified id.

Script zendesk Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 398 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Merge Tickets into Target Ticket
8
 * Merges one or more tickets into the ticket with the specified id.
9
 */
10
export async function main(
11
  auth: Zendesk,
12
  ticket_id: string,
13
  body: {
14
    ids?: string;
15
    source_comment?: string;
16
    source_comment_is_public?: string;
17
    target_comment?: string;
18
    target_comment_is_public?: string;
19
    [k: string]: unknown;
20
  }
21
) {
22
  const url = new URL(
23
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/merge`
24
  );
25

26
  const response = await fetch(url, {
27
    method: "POST",
28
    headers: {
29
      "Content-Type": "application/json",
30
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
31
    },
32
    body: JSON.stringify(body),
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40