0

Email statement

by
Published Oct 17, 2025

Email statement to the contact. If JSONString is not inputted, mail will be sent with the 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 statement
7
 * Email statement to the contact. If JSONString is not inputted, mail will be sent with the default mail content.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  contact_id: string,
12
  organization_id: string | undefined,
13
  start_date: string | undefined,
14
  end_date: string | undefined,
15
  multipart_or_formdata: string | undefined,
16
  body: {
17
    send_from_org_email_id?: false | true;
18
    to_mail_ids: string[];
19
    cc_mail_ids?: string[];
20
    subject: string;
21
    body: string;
22
  },
23
) {
24
  const url = new URL(
25
    `https://www.zohoapis.com/inventory/v1/contacts/${contact_id}/statements/email`,
26
  );
27
  for (const [k, v] of [
28
    ["organization_id", organization_id],
29
    ["start_date", start_date],
30
    ["end_date", end_date],
31
    ["multipart_or_formdata", multipart_or_formdata],
32
  ]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Zoho-oauthtoken " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51