0

Update KObject (custom object) by ID

by
Published Oct 17, 2025

Updates an existing KObject (custom object) based on the unique ID.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update KObject (custom object) by ID
7
 * Updates an existing KObject (custom object) based on the unique ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  name: string,
12
  id: string,
13
  body: {
14
    externalId?: string;
15
    title?: string;
16
    description?: string;
17
    images?: string[];
18
    icon?: string;
19
    data?: {};
20
    custom?: {};
21
    tags?: string[];
22
    createdAt?: string;
23
    importedAt?: string;
24
    rev?: number;
25
  },
26
) {
27
  const url = new URL(`https://api.kustomerapp.com/v1/klasses/${name}/${id}`);
28

29
  const response = await fetch(url, {
30
    method: "PUT",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.apiKey,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43