0

Create conversation

by
Published Oct 17, 2025

Creates a new 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 conversation
7
 * Creates a new conversation.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  body: {
12
    id?: string;
13
    customer: string;
14
    externalId?: string;
15
    name?: string;
16
    status?: "open" | "done";
17
    priority?: number;
18
    createdAt?: string;
19
    importedAt?: string;
20
    direction?: "in" | "out";
21
    replyChannel?: string;
22
    tags?: string[];
23
    assignedUsers?: string[];
24
    assignedTeams?: string[];
25
    custom?: {};
26
    defaultLang?: string;
27
    queue?: {};
28
  },
29
) {
30
  const url = new URL(`https://api.kustomerapp.com/v1/conversations`);
31

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