0

Bulk batch update KObjects (custom objects)

by
Published Oct 17, 2025

Updates a bulk batch of multiple KObjects (custom objects). Use the `ids` query param to update multiple KObjects in bulk with the same data. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.kobject.write|org.permission.kobject.update| ||org.permission.kobject.kobject_*.update|

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Bulk batch update KObjects (custom objects)
7
 * Updates a bulk batch of multiple KObjects (custom objects).
8

9
Use the `ids` query param to update multiple KObjects in bulk with the same data.
10

11
Any one of the following roles is required for this endpoint:
12

13
|Legacy Role|Equivalent Permission Set Role|
14
|-----|--------|
15
|org.user.kobject.write|org.permission.kobject.update|
16
||org.permission.kobject.kobject_*.update|
17
 */
18
export async function main(
19
  auth: Kustomer,
20
  name: string,
21
  ids: string | undefined,
22
  body: {
23
    id: string;
24
    externalId?: string;
25
    title?: string;
26
    description?: string;
27
    images?: string[];
28
    icon?: string;
29
    data?: {};
30
    custom?: {};
31
    tags?: string[];
32
    createdAt?: string;
33
    importedAt?: string;
34
    rev?: number;
35
  }[],
36
) {
37
  const url = new URL(`https://api.kustomerapp.com/v1/klasses/${name}/bulk`);
38
  for (const [k, v] of [["ids", ids]]) {
39
    if (v !== undefined && v !== "" && k !== undefined) {
40
      url.searchParams.append(k, v);
41
    }
42
  }
43
  const response = await fetch(url, {
44
    method: "PUT",
45
    headers: {
46
      "Content-Type": "application/json",
47
      Authorization: "Bearer " + auth.apiKey,
48
    },
49
    body: JSON.stringify(body),
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.json();
56
}
57