0

Bulk batch update messages

by
Published Oct 17, 2025

Updates a bulk batch of messages. Use the `ids` query param to update multiple messages 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.message.write|org.permission.message.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 messages
7
 * Updates a bulk batch of messages.
8

9
Use the `ids` query param to update multiple messages 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.message.write|org.permission.message.update|
16
 */
17
export async function main(
18
  auth: Kustomer,
19
  ids: string | undefined,
20
  body: {
21
    id: string;
22
    conversation?: string;
23
    externalId?: string;
24
    preview?: string;
25
    subject?: string;
26
    status?: "sent" | "received" | "error";
27
    error?: {
28
      status?: number;
29
      code?: string;
30
      title?: string;
31
      detail?: string;
32
      source?: {};
33
      meta?: {};
34
      links?: {};
35
    };
36
    errorAt?: string;
37
    sentAt?: string;
38
    size?: number;
39
    attachments?: {
40
      _id: string;
41
      name: string;
42
      contentType: string;
43
      contentLength: number;
44
      sourceId?: string;
45
    }[];
46
    meta?: {};
47
    custom?: {};
48
    related?: string;
49
    sentiment?: { polarity: 0 | 1 | -1; confidence: number };
50
    createdAt?: string;
51
    modifiedAt?: string;
52
    updatedAt?: string;
53
    createdBy?: string;
54
    modifiedBy?: string;
55
    lang?: string;
56
  }[],
57
) {
58
  const url = new URL(`https://api.kustomerapp.com/v1/messages/bulk`);
59
  for (const [k, v] of [["ids", ids]]) {
60
    if (v !== undefined && v !== "" && k !== undefined) {
61
      url.searchParams.append(k, v);
62
    }
63
  }
64
  const response = await fetch(url, {
65
    method: "PUT",
66
    headers: {
67
      "Content-Type": "application/json",
68
      Authorization: "Bearer " + auth.apiKey,
69
    },
70
    body: JSON.stringify(body),
71
  });
72
  if (!response.ok) {
73
    const text = await response.text();
74
    throw new Error(`${response.status} ${text}`);
75
  }
76
  return await response.json();
77
}
78