0

Get attachments

by
Published Oct 17, 2025
Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Get attachments
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  _module: string,
12
  record_id: string,
13
  fields: string,
14
  ids: string | undefined,
15
  page: string | undefined,
16
  per_page: string | undefined,
17
  page_token: string | undefined,
18
) {
19
  const url = new URL(
20
    `https://zohoapis.com/crm/v8/${_module}/${record_id}/Attachments`,
21
  );
22
  for (const [k, v] of [
23
    ["fields", fields],
24
    ["ids", ids],
25
    ["page", page],
26
    ["per_page", per_page],
27
    ["page_token", page_token],
28
  ]) {
29
    if (v !== undefined && v !== "" && k !== undefined) {
30
      url.searchParams.append(k, v);
31
    }
32
  }
33
  const response = await fetch(url, {
34
    method: "GET",
35
    headers: {
36
      Authorization: "Zoho-oauthtoken " + auth.token,
37
    },
38
    body: undefined,
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