0

Create forward attachment

by
Published Oct 17, 2025

Creates an attachment on a forward. ## Pre-signed URL When you create an attachment, the response will include a **related** URL in the **links** section. You ca use this URL to upload the contents of the attachment. This URL is a Pre-Signed URL from S3 and provides access to upload a file for a limited duration. ### Example command to upload an attachment to the related Pre-Signed URL ```bash $ curl --upload-file [full path to file] "[Pre-Signed URL]" ```

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 forward attachment
7
 * Creates an attachment on a forward.
8

9
## Pre-signed URL
10

11
When you create an attachment, the response will include a **related** URL in the **links** section. You ca use this URL to upload the contents of the attachment. This URL is a Pre-Signed URL from S3 and provides access to upload a file for a limited duration.
12

13
### Example command to upload an attachment to the related Pre-Signed URL
14

15
```bash
16
$ curl --upload-file [full path to file] "[Pre-Signed URL]"
17
```
18
 */
19
export async function main(
20
  auth: Kustomer,
21
  id: string,
22
  body: { name: string; contentType: string; contentLength: number },
23
) {
24
  const url = new URL(
25
    `https://api.kustomerapp.com/v1/forwards/${id}/attachments`,
26
  );
27

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