Update Custom Object Field

Updates individual custom object fields. The updating rules are as follows: * Takes a `custom_object_field` object that specifies the properties to update * The `key` property cannot be updated * If updating a standard field, only the `title` and `description` properties can be updated. #### 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 Custom Object Field
8
 * Updates individual custom object fields. The updating rules are as follows:
9
* Takes a `custom_object_field` object that specifies the properties to update
10
* The `key` property cannot be updated
11
* If updating a standard field, only the `title` and `description` properties can be updated.
12
#### Allowed For
13
* Admins
14
 */
15
export async function main(
16
  auth: Zendesk,
17
  custom_object_key: string,
18
  custom_object_field_key_or_id: string
19
) {
20
  const url = new URL(
21
    `https://${auth.subdomain}.zendesk.com/api/v2/custom_objects/${custom_object_key}/fields/${custom_object_field_key_or_id}`
22
  );
23

24
  const response = await fetch(url, {
25
    method: "PATCH",
26
    headers: {
27
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37