0

Get related record

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 related record
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  module_api_name: string,
12
  record_id: string,
13
  related_list_api_name: string,
14
  related_record_id: string,
15
  fields: string | undefined,
16
  If_Modified_Since?: string,
17
  X_EXTERNAL?: string,
18
) {
19
  const url = new URL(
20
    `https://zohoapis.com/crm/v8/${module_api_name}/${record_id}/${related_list_api_name}/${related_record_id}`,
21
  );
22
  for (const [k, v] of [["fields", fields]]) {
23
    if (v !== undefined && v !== "" && k !== undefined) {
24
      url.searchParams.append(k, v);
25
    }
26
  }
27
  const response = await fetch(url, {
28
    method: "GET",
29
    headers: {
30
      ...(If_Modified_Since ? { "If-Modified-Since": If_Modified_Since } : {}),
31
      ...(X_EXTERNAL ? { "X-EXTERNAL": X_EXTERNAL } : {}),
32
      Authorization: "Zoho-oauthtoken " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.json();
41
}
42