Edits history of script submission #20543 for ' Send report via email (smartsheet)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Smartsheet = {
      token: string;
      baseUrl: string;
    };
    /**
     * Send report via email
     * Sends the report as a PDF attachment via email to the designated recipients
     */
    export async function main(
      auth: Smartsheet,
      reportId: string,
      body: {
        ccMe?: false | true;
        message?: string;
        sendTo?: { email?: string } | { groupId?: number }[];
        subject?: string;
      } & {
        format?: string;
        formatDetails?: {
          paperSize?:
            | "A0"
            | "A1"
            | "A2"
            | "A3"
            | "A4"
            | "ARCHID"
            | "LEGAL"
            | "LETTER"
            | "WIDE";
        };
      },
    ) {
      const url = new URL(`${auth.baseUrl}/reports/${reportId}/emails`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago