Edits history of script submission #21440 for ' Email an invoice (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Email an invoice
     * Email an invoice to the customer. Input json string is not mandatory. If input json string is empty, mail will be send with default mail content.
     */
    export async function main(
      auth: Zoho,
      invoice_id: string,
      organization_id: string | undefined,
      send_customer_statement: string | undefined,
      send_attachment: string | undefined,
      attachments: string | undefined,
      body: {
        send_from_org_email_id?: false | true;
        to_mail_ids: string[];
        cc_mail_ids?: string[];
        subject?: string;
        body?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/invoices/${invoice_id}/email`,
      );
      for (const [k, v] of [
        ["organization_id", organization_id],
        ["send_customer_statement", send_customer_statement],
        ["send_attachment", send_attachment],
        ["attachments", attachments],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + 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