0

Add attachment to a journal

by
Published Oct 17, 2025

Attach a file to a journal.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Add attachment to a journal
7
 * Attach a file to a journal.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  journal_id: string,
12
  organization_id: string | undefined,
13
  attachment: string | undefined,
14
  doc: string | undefined,
15
  totalFiles: string | undefined,
16
  document_ids: string | undefined,
17
) {
18
  const url = new URL(
19
    `https://www.zohoapis.com/books/v3/journals/${journal_id}/attachment`,
20
  );
21
  for (const [k, v] of [
22
    ["organization_id", organization_id],
23
    ["attachment", attachment],
24
    ["doc", doc],
25
    ["totalFiles", totalFiles],
26
    ["document_ids", document_ids],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "POST",
34
    headers: {
35
      Authorization: "Zoho-oauthtoken " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45