Update Attachment for Malware

Toggles enabling or restricting agent access to attachments with detected malware. #### Allowed For * Admins

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Update Attachment for Malware
8
 * Toggles enabling or restricting agent access to attachments with detected malware.
9

10
#### Allowed For
11

12
* Admins
13

14
 */
15
export async function main(
16
  auth: Zendesk,
17
  attachment_id: string,
18
  body: {
19
    attachment?: { malware_access_override?: string; [k: string]: unknown };
20
    [k: string]: unknown;
21
  }
22
) {
23
  const url = new URL(
24
    `https://${auth.subdomain}.zendesk.com/api/v2/attachments/${attachment_id}`
25
  );
26

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