0

Get attachment

by
Published Oct 17, 2025

Get attachment

Script holded Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Holded = {
3
  apiKey: string;
4
};
5
/**
6
 * Get attachment
7
 * Get attachment
8
 */
9
export async function main(
10
  auth: Holded,
11
  contactId: string,
12
  filename: string | undefined,
13
) {
14
  const url = new URL(
15
    `https://api.holded.com/api/invoicing/v1/contacts/${contactId}/attachments/get`,
16
  );
17
  for (const [k, v] of [["filename", filename]]) {
18
    if (v !== undefined && v !== "" && k !== undefined) {
19
      url.searchParams.append(k, v);
20
    }
21
  }
22
  const response = await fetch(url, {
23
    method: "GET",
24
    headers: {
25
      key: auth.apiKey,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35