0

Create note within conversation

by
Published Oct 17, 2025

Creates a new note within a conversation.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Create note within conversation
7
 * Creates a new note within a conversation.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    id?: string;
14
    conversation?: string;
15
    externalId?: string;
16
    body: string;
17
    userMentions?: { user?: string; team?: string }[];
18
    attachments?: {
19
      _id: string;
20
      name: string;
21
      contentType: string;
22
      contentLength: number;
23
      sourceId?: string;
24
    }[];
25
    createdAt?: string;
26
    modifiedAt?: string;
27
    createdBy?: string;
28
    modifiedBy?: string;
29
    importedAt?: string;
30
    lang?: string;
31
  },
32
) {
33
  const url = new URL(
34
    `https://api.kustomerapp.com/v1/conversations/${id}/notes`,
35
  );
36

37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Bearer " + auth.apiKey,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51