0

Set Ticket Attribute Values

by
Published Nov 7, 2023

Adds the specified attributes if no attributes exists, or replaces all existing attributes with the specified attributes. Invalid or deleted attributes are ignored. #### Allowed For * Admins

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
 * Set Ticket Attribute Values
8
 * Adds the specified attributes if no attributes exists, or replaces all existing attributes with the specified attributes.
9

10
Invalid or deleted attributes are ignored.
11

12
#### Allowed For
13

14
* Admins
15

16
 */
17
export async function main(auth: Zendesk, ticket_id: string) {
18
  const url = new URL(
19
    `https://${auth.subdomain}.zendesk.com/api/v2/routing/tickets/${ticket_id}/instance_values`
20
  );
21

22
  const response = await fetch(url, {
23
    method: "POST",
24
    headers: {
25
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35