0

Create conversation for customer

by
Published Oct 17, 2025

Creates a new, empty conversation for a customer.

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

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