Update Custom Object

Updates an individual custom object. The updating rules are as follows: * Takes a `custom_object` object that specifies the properties to update * The `key` property cannot 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
8
 * Updates an individual custom object. The updating rules are as follows:
9
* Takes a `custom_object` object that specifies the properties to update
10
* The `key` property cannot be updated
11
#### Allowed For
12
* Admins
13
 */
14
export async function main(auth: Zendesk, custom_object_key: string) {
15
  const url = new URL(
16
    `https://${auth.subdomain}.zendesk.com/api/v2/custom_objects/${custom_object_key}`
17
  );
18

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