Create User Field

Creates any of the following custom field types: * text (default when no "type" is specified) * textarea * checkbox * date * integer * decimal * regexp * dropdown * lookup See [About custom field types](https://support.zendesk.com/hc/en-us/articles/203661866) in Zendesk help. #### 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 User Field
8
 * Creates any of the following custom field types:
9

10
* text (default when no "type" is specified)
11
* textarea
12
* checkbox
13
* date
14
* integer
15
* decimal
16
* regexp
17
* dropdown
18
* lookup
19

20
See [About custom field types](https://support.zendesk.com/hc/en-us/articles/203661866) in Zendesk help.
21

22
#### Allowed For
23

24
* Admins
25

26
 */
27
export async function main(auth: Zendesk) {
28
  const url = new URL(
29
    `https://${auth.subdomain}.zendesk.com/api/v2/user_fields`
30
  );
31

32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45