0

Update note by ID

by
Published Oct 17, 2025

Updates a note based on the unique note 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 note by ID
7
 * Updates a note based on the unique note ID.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  replace: string | undefined,
13
  body: {
14
    conversation: string;
15
    externalId?: string;
16
    body: string;
17
    userMentions?: { user?: string; team?: string }[];
18
    deleted?: false | true;
19
    attachments?: {
20
      _id: string;
21
      name: string;
22
      contentType: string;
23
      contentLength: number;
24
      sourceId?: string;
25
    }[];
26
    createdAt?: string;
27
    modifiedAt?: string;
28
    updatedAt?: string;
29
    createdBy?: string;
30
    modifiedBy?: string;
31
    lang?: string;
32
  },
33
) {
34
  const url = new URL(`https://api.kustomerapp.com/v1/notes/${id}`);
35
  for (const [k, v] of [["replace", replace]]) {
36
    if (v !== undefined && v !== "") {
37
      url.searchParams.append(k, v);
38
    }
39
  }
40
  const response = await fetch(url, {
41
    method: "PUT",
42
    headers: {
43
      "Content-Type": "application/json",
44
      Authorization: "Bearer " + auth.apiKey,
45
    },
46
    body: JSON.stringify(body),
47
  });
48
  if (!response.ok) {
49
    const text = await response.text();
50
    throw new Error(`${response.status} ${text}`);
51
  }
52
  return await response.json();
53
}
54