0

Email a quote

by
Published Oct 17, 2025

Email a quote to the customer. Input json string is not mandatory. If input json string is empty, mail will be send with default mail content.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Email a quote
7
 * Email a quote to the customer. Input json string is not mandatory. If input json string is empty, mail will be send with default mail content.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  estimate_id: string,
12
  attachments: string | undefined,
13
  X_com_zoho_subscriptions_organizationid: string,
14
  body: {
15
    send_from_org_email_id?: false | true;
16
    to_mail_ids: string[];
17
    cc_mail_ids?: string[];
18
    subject?: string;
19
    body?: string;
20
  },
21
) {
22
  const url = new URL(
23
    `https://www.zohoapis.com/billing/v1/estimates/${estimate_id}/email`,
24
  );
25
  for (const [k, v] of [["attachments", attachments]]) {
26
    if (v !== undefined && v !== "" && k !== undefined) {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "POST",
32
    headers: {
33
      "X-com-zoho-subscriptions-organizationid":
34
        X_com_zoho_subscriptions_organizationid,
35
      "Content-Type": "application/json",
36
      Authorization: "Zoho-oauthtoken " + auth.token,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46