Edits history of script submission #23838 for ' Remove Ticket Tags (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Remove Ticket Tags
     * Remove tags from a ticket; tags it doesn't have are ignored. Returns the ticket's remaining tags.
     */
    export async function main(
      auth: RT.Zendesk,
      ticket_id: number,
      tags: string[]
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/tags`
      )
      url.searchParams.append("tags", tags.join(","))
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: auth.token
            ? `Bearer ${auth.token}`
            : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago