0

Get draft attachment

by
Published Oct 17, 2025

Retrieves a draft attachment. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.attachment.read|org.permission.attachment.read| ### Pre-signed URL When you request the resource, the response will include a **related** URL in the **links** section. You can use this URL to download the attachment file. This URL is a Pre-Signed URL from S3 and provides access for a limited duration to download a file.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Get draft attachment
7
 * Retrieves a draft attachment.
8

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

11
|Legacy Role|Equivalent Permission Set Role|
12
|-----|--------|
13
|org.user.attachment.read|org.permission.attachment.read|
14

15
### Pre-signed URL
16

17
When you request the resource, the response will include a **related** URL in the **links** section. You can use this URL to download the attachment file.  This URL is a Pre-Signed URL from S3 and provides access for a limited duration to download a file.
18
 */
19
export async function main(auth: Kustomer, id: string, attachmentId: string) {
20
  const url = new URL(
21
    `https://api.kustomerapp.com/v1/drafts/${id}/attachments/${attachmentId}`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "GET",
26
    headers: {
27
      Authorization: "Bearer " + auth.apiKey,
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37