0

Bulk batch update conversations

by
Published Oct 17, 2025

Updates a bulk batch of conversations. Use the `ids` query param to update multiple conversations in bulk with the same data. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.conversation.write|org.permission.conversation.update|

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Bulk batch update conversations
7
 * Updates a bulk batch of conversations.
8

9
Use the `ids` query param to update multiple conversations in bulk with the same data.
10

11
Any one of the following roles is required for this endpoint:
12

13
|Legacy Role|Equivalent Permission Set Role|
14
|-----|--------|
15
|org.user.conversation.write|org.permission.conversation.update|
16
 */
17
export async function main(
18
  auth: Kustomer,
19
  ids: string | undefined,
20
  body:
21
    | {
22
        id: string;
23
        externalId?: string;
24
        name?: string;
25
        direction?: "in" | "out";
26
        priority?: number;
27
        satisfaction?: number;
28
        status?: "open" | "snoozed" | "done";
29
        replyChannel?: string;
30
        subStatus?: string;
31
        snooze?: {
32
          time?: string;
33
          status: "scheduled" | "canceled" | "elapsed";
34
        };
35
        tags?: string[];
36
        suggestedTags?: { tag: string; confidence: number }[];
37
        sentiment?: { polarity: 0 | 1 | -1; confidence: number };
38
        assignedUsers?: string[];
39
        assignedTeams?: string[];
40
        custom?: {};
41
        deleted?: false | true;
42
        ended?: false | true;
43
        endedAt?: string;
44
        endedReason?: string;
45
        endedBy?: string;
46
        endedByType?: "user" | "customer";
47
        locked?: false | true;
48
        rev?: number;
49
        defaultLang?: string;
50
        queue?: {} | {};
51
      }
52
    | { id: string; customer?: string }[],
53
) {
54
  const url = new URL(`https://api.kustomerapp.com/v1/conversations/bulk`);
55
  for (const [k, v] of [["ids", ids]]) {
56
    if (v !== undefined && v !== "" && k !== undefined) {
57
      url.searchParams.append(k, v);
58
    }
59
  }
60
  const response = await fetch(url, {
61
    method: "PUT",
62
    headers: {
63
      "Content-Type": "application/json",
64
      Authorization: "Bearer " + auth.apiKey,
65
    },
66
    body: JSON.stringify(body),
67
  });
68
  if (!response.ok) {
69
    const text = await response.text();
70
    throw new Error(`${response.status} ${text}`);
71
  }
72
  return await response.json();
73
}
74