0

Email a credit note

by
Published Oct 17, 2025

Email a credit note.

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 credit note
7
 * Email a credit note.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  creditnote_id: string,
12
  organization_id: string | undefined,
13
  customer_id: string | undefined,
14
  attachments: string | undefined,
15
  body: {
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/inventory/v1/creditnotes/${creditnote_id}/email`,
24
  );
25
  for (const [k, v] of [
26
    ["organization_id", organization_id],
27
    ["customer_id", customer_id],
28
    ["attachments", attachments],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "POST",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Zoho-oauthtoken " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48