0

Send Document

by
Published Oct 17, 2025

Send a specific document by email.

Script holded Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Holded = {
3
  apiKey: string;
4
};
5
/**
6
 * Send Document
7
 * Send a specific document by email.
8
 */
9
export async function main(
10
  auth: Holded,
11
  docType: string,
12
  documentId: string,
13
  body: {
14
    mailTemplateId?: string;
15
    emails: string;
16
    subject?: string;
17
    message?: string;
18
    docIds?: string;
19
  },
20
) {
21
  const url = new URL(
22
    `https://api.holded.com/api/invoicing/v1/documents/${docType}/${documentId}/send`,
23
  );
24

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