0

Get scoring rules

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 scoring rules
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  _module: string | undefined,
12
  layout_id: string | undefined,
13
  active: "false" | "true" | undefined,
14
  name: string | undefined,
15
  page: string | undefined,
16
  per_page: string | undefined,
17
) {
18
  const url = new URL(
19
    `https://zohoapis.com/crm/v8/settings/automation/scoring_rules`,
20
  );
21
  for (const [k, v] of [
22
    ["module", _module],
23
    ["layout_id", layout_id],
24
    ["active", active],
25
    ["name", name],
26
    ["page", page],
27
    ["per_page", per_page],
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