0

Set Ticket Tags

by
Published Nov 7, 2023

Replace all of a ticket's tags with the given list. Returns the ticket's new tag list.

Script zendesk Verified

The script

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

3
/**
4
 * Set Ticket Tags
5
 * Replace all of a ticket's tags with the given list. Returns the ticket's new tag list.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  tags: string[]
11
) {
12
  const response = await fetch(
13
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags`,
14
    {
15
      method: "POST",
16
      headers: {
17
        Authorization: auth.token
18
          ? `Bearer ${auth.token}`
19
          : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
20
        "Content-Type": "application/json",
21
        Accept: "application/json",
22
      },
23
      body: JSON.stringify({ tags }),
24
    }
25
  )
26

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

31
  return await response.json()
32
}
33

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * Set Tags
    8
     * #### Allowed For
    9
    
    
    10
    * Agents
    11
    
    
    12
     */
    13
    export async function main(auth: Zendesk, ticket_id: string) {
    14
      const url = new URL(
    15
        `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags`
    16
      );
    17
    
    
    18
      const response = await fetch(url, {
    19
        method: "POST",
    20
        headers: {
    21
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    22
        },
    23
        body: undefined,
    24
      });
    25
      if (!response.ok) {
    26
        const text = await response.text();
    27
        throw new Error(`${response.status} ${text}`);
    28
      }
    29
      return await response.json();
    30
    }
    31