0

Send Sheet via Email

by
Published Oct 17, 2025

Sends the sheet as a PDF attachment via email to the designated recipients.

Script smartsheet Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Smartsheet = {
3
  token: string;
4
  baseUrl: string;
5
};
6
/**
7
 * Send Sheet via Email
8
 * Sends the sheet as a PDF attachment via email to the designated recipients.
9
 */
10
export async function main(
11
  auth: Smartsheet,
12
  sheetId: string,
13
  body: {
14
    ccMe?: false | true;
15
    message?: string;
16
    sendTo?: { email?: string } | { groupId?: number }[];
17
    subject?: string;
18
  } & {
19
    format?: string;
20
    formatDetails?: {
21
      paperSize?:
22
        | "A0"
23
        | "A1"
24
        | "A2"
25
        | "A3"
26
        | "A4"
27
        | "ARCHID"
28
        | "LEGAL"
29
        | "LETTER"
30
        | "WIDE";
31
    };
32
  },
33
) {
34
  const url = new URL(`${auth.baseUrl}/sheets/${sheetId}/emails`);
35

36
  const response = await fetch(url, {
37
    method: "POST",
38
    headers: {
39
      "Content-Type": "application/json",
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: JSON.stringify(body),
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50