0

Update shift hour

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
 * Update shift hour
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  shift_id: string,
12
  body: {
13
    shift_hours?: {
14
      same_as_everyday: false | true;
15
      shift_days: string[];
16
      daily_timing: {}[];
17
      custom_timing: { days: string; shift_timing: {}[] }[];
18
      id: string;
19
      break_hours: {
20
        break_days: string[];
21
        same_as_everyday: false | true;
22
        daily_timing: {}[];
23
        custom_timing: { days: string; break_timing: {}[] }[];
24
        id: string;
25
      }[];
26
      users: {
27
        role: { name: string; id: string };
28
        name: string;
29
        id: string;
30
        email: string;
31
        zuid: string;
32
        effective_from: string;
33
      }[];
34
      holidays: { date: string; year: number; name: string; id: string }[];
35
      users_count: number;
36
      timezone: {};
37
      name: string;
38
    }[];
39
  },
40
  X_CRM_ORG?: string,
41
) {
42
  const url = new URL(
43
    `https://zohoapis.com/crm/v8/settings/business_hours/shift_hours/${shift_id}`,
44
  );
45

46
  const response = await fetch(url, {
47
    method: "PUT",
48
    headers: {
49
      ...(X_CRM_ORG ? { "X-CRM-ORG": X_CRM_ORG } : {}),
50
      "Content-Type": "application/json",
51
      Authorization: "Zoho-oauthtoken " + auth.token,
52
    },
53
    body: JSON.stringify(body),
54
  });
55
  if (!response.ok) {
56
    const text = await response.text();
57
    throw new Error(`${response.status} ${text}`);
58
  }
59
  return await response.json();
60
}
61