Create 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
 * Create Workspace
8
 * #### Allowed For
9

10
* Admins
11

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

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