Update Workspace

#### 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 Workspace
8
 * #### Allowed For
9
 * Admins
10
 */
11
export async function main(
12
  auth: Zendesk,
13
  workspace_id: string,
14
  body: {
15
    workspace?: {
16
      conditions?: {
17
        all?: {
18
          field?: string;
19
          operator?: string;
20
          value?: string;
21
          [k: string]: unknown;
22
        }[];
23
        any?: {
24
          field?: string;
25
          operator?: string;
26
          value?: string;
27
          [k: string]: unknown;
28
        }[];
29
        [k: string]: unknown;
30
      };
31
      description?: string;
32
      macros?: string[];
33
      ticket_form_id?: string;
34
      title?: string;
35
      [k: string]: unknown;
36
    };
37
    [k: string]: unknown;
38
  }
39
) {
40
  const url = new URL(
41
    `https://${auth.subdomain}.zendesk.com/api/v2/workspaces/${workspace_id}`
42
  );
43

44
  const response = await fetch(url, {
45
    method: "PUT",
46
    headers: {
47
      "Content-Type": "application/json",
48
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
49
    },
50
    body: JSON.stringify(body),
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.json();
57
}
58