Custom Object Record Bulk Jobs

Queues a background job to perform bulk actions on up to 100 custom object records per single request.

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
 * Custom Object Record Bulk Jobs
8
 * Queues a background job to perform bulk actions on up to 100 custom object records per single request.
9
 */
10
export async function main(
11
  auth: Zendesk,
12
  custom_object_key: string,
13
  body: {
14
    job?: {
15
      action?: string;
16
      items?: {
17
        created_at?: string;
18
        created_by_user_id?: string;
19
        custom_object_fields?: {
20
          dolor_2?: string;
21
          eu_81?: string;
22
          officia_cda?: string;
23
          suntbba?: string;
24
          [k: string]: unknown;
25
        };
26
        custom_object_key?: string;
27
        external_id?: string;
28
        id?: string;
29
        name?: string;
30
        updated_at?: string;
31
        updated_by_user_id?: string;
32
        url?: string;
33
        [k: string]: unknown;
34
      }[];
35
      [k: string]: unknown;
36
    };
37
    [k: string]: unknown;
38
  }
39
) {
40
  const url = new URL(
41
    `https://${auth.subdomain}.zendesk.com/api/v2/custom_objects/${custom_object_key}/jobs`
42
  );
43

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