0

Remove Ticket Tags

by
Published Nov 7, 2023

Remove tags from a ticket; tags it doesn't have are ignored. Returns the ticket's remaining tags.

Script zendesk Verified

The script

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

3
/**
4
 * Remove Ticket Tags
5
 * Remove tags from a ticket; tags it doesn't have are ignored. Returns the ticket's remaining tags.
6
 */
7
export async function main(
8
  auth: RT.Zendesk,
9
  ticket_id: number,
10
  tags: string[]
11
) {
12
  const url = new URL(
13
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags`
14
  )
15
  url.searchParams.append("tags", tags.join(","))
16

17
  const response = await fetch(url, {
18
    method: "DELETE",
19
    headers: {
20
      Authorization: auth.token
21
        ? `Bearer ${auth.token}`
22
        : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
23
      Accept: "application/json",
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
     * Remove Tags
    8
     * You can also delete tags from multiple tickets with the
    9
    Update Many Tickets endpoint.
    10
    
    
    11
    This endpoint supports safe updates. See Safe Update.
    12
    
    
    13
    #### Allowed For
    14
    
    
    15
    * Agents
    16
    
    
    17
     */
    18
    export async function main(auth: Zendesk, ticket_id: string) {
    19
      const url = new URL(
    20
        `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags`
    21
      );
    22
    
    
    23
      const response = await fetch(url, {
    24
        method: "DELETE",
    25
        headers: {
    26
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    27
        },
    28
        body: undefined,
    29
      });
    30
      if (!response.ok) {
    31
        const text = await response.text();
    32
        throw new Error(`${response.status} ${text}`);
    33
      }
    34
      return await response.text();
    35
    }
    36