0

Get holidays

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 holidays
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  year: string | undefined,
12
  _type: "business_holiday" | "shift_holiday" | undefined,
13
  shift_id: string | undefined,
14
  X_CRM_ORG?: string,
15
) {
16
  const url = new URL(`https://zohoapis.com/crm/v8/settings/holidays`);
17
  for (const [k, v] of [
18
    ["year", year],
19
    ["type", _type],
20
    ["shift_id", shift_id],
21
  ]) {
22
    if (v !== undefined && v !== "" && k !== undefined) {
23
      url.searchParams.append(k, v);
24
    }
25
  }
26
  const response = await fetch(url, {
27
    method: "GET",
28
    headers: {
29
      ...(X_CRM_ORG ? { "X-CRM-ORG": X_CRM_ORG } : {}),
30
      Authorization: "Zoho-oauthtoken " + auth.token,
31
    },
32
    body: undefined,
33
  });
34
  if (!response.ok) {
35
    const text = await response.text();
36
    throw new Error(`${response.status} ${text}`);
37
  }
38
  return await response.json();
39
}
40