0

Update or upsert attachment

by
Published Oct 17, 2025

Updates the requested attachment. Upserts the attachment if an attachment does not exist. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.admin.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
 * Update or upsert attachment
7
 * Updates the requested attachment. Upserts the attachment if an attachment does not exist.
8

9
Any one of the following roles is required for this endpoint:
10

11
|Legacy Role|Equivalent Permission Set Role|
12
|-----|--------|
13
|org.admin.message.write|org.permission.message.update|
14
 */
15
export async function main(
16
  auth: Kustomer,
17
  id: string,
18
  body: {
19
    name?: string;
20
    redacted?: false | true;
21
    contentType?: string;
22
    contentLength?: number;
23
  },
24
) {
25
  const url = new URL(`https://api.kustomerapp.com/v1/attachments/${id}`);
26

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