Create Custom Object

Creates an object describing all the properties required to create a custom object record #### 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 Custom Object
8
 * Creates an object describing all the properties required to create a custom object record
9
#### Allowed For
10
* Admins
11

12
 */
13
export async function main(
14
  auth: Zendesk,
15
  body: {
16
    custom_object?: {
17
      key?: string;
18
      title?: string;
19
      title_pluralized?: string;
20
      [k: string]: unknown;
21
    };
22
    [k: string]: unknown;
23
  }
24
) {
25
  const url = new URL(
26
    `https://${auth.subdomain}.zendesk.com/api/v2/custom_objects`
27
  );
28

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