0

Update territory users

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 territory users
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  territory: string,
12
  body: {
13
    users?: {
14
      country?: string;
15
      language?: string;
16
      microsoft?: false | true;
17
      $shift_effective_from?: {};
18
      id?: string;
19
      state?: string;
20
      fax?: string;
21
      country_locale?: string;
22
      zip?: string;
23
      created_time?: string;
24
      time_format?: "HH:mm" | "hh:mm a";
25
      offset?: number;
26
      profile?: { name: string; id: string };
27
      role?: { name: string; id: string };
28
      created_by?: { name: string; id: string; email?: string };
29
      full_name?: string;
30
      zuid?: string;
31
      phone?: string;
32
      dob?: string;
33
      status?: string;
34
      customize_info?: {
35
        notes_desc: {};
36
        show_right_panel: {};
37
        bc_view: {};
38
        unpin_recent_item: {};
39
        show_home: false | true;
40
        show_detail_view: false | true;
41
      };
42
      city?: string;
43
      signature?: string;
44
      sort_order_preference__s?: string;
45
      category?: string;
46
      date_format?: "MMM d, yyyy";
47
      confirm?: false | true;
48
      decimal_separator?: "Comma" | "Period";
49
      number_separator?: "Space";
50
      time_zone?: {};
51
      last_name?: string;
52
      mobile?: string;
53
      $current_shift?: { name: string; id: string };
54
      Reporting_To?: { name: string; id: string; email?: string };
55
      Currency?: string;
56
      $next_shift?: { name: string; id: string };
57
      Modified_Time?: string;
58
      website?: string;
59
      status_reason__s?: string;
60
      email?: string;
61
      first_name?: string;
62
      sandboxDeveloper?: false | true;
63
      alias?: string;
64
      street?: string;
65
      Modified_By?: {
66
        name: string;
67
        id: string;
68
        last_name: string;
69
        first_name: string;
70
      };
71
      Isonline?: false | true;
72
      locale?: string;
73
      name_format__s?:
74
        | "Salutation,First Name,Last Name"
75
        | "Saluation,Last Name,First Name"
76
        | "First Name,Last Name,Saluation";
77
      personal_account?: false | true;
78
      default_tab_group?: string;
79
      theme?: {
80
        normal_tab: { font_color: "#FFFFFF"; background: "#222222" };
81
        selected_tab: { font_color: "#FFFFFF"; background: "#222222" };
82
        new_background: string;
83
        background: "#F3F0EB";
84
        screen: "fixed";
85
        type: string;
86
      };
87
      sort_order_preference?: string;
88
    }[];
89
  },
90
) {
91
  const url = new URL(
92
    `https://zohoapis.com/crm/v8/settings/territories/${territory}/users`,
93
  );
94

95
  const response = await fetch(url, {
96
    method: "PUT",
97
    headers: {
98
      "Content-Type": "application/json",
99
      Authorization: "Zoho-oauthtoken " + auth.token,
100
    },
101
    body: JSON.stringify(body),
102
  });
103
  if (!response.ok) {
104
    const text = await response.text();
105
    throw new Error(`${response.status} ${text}`);
106
  }
107
  return await response.json();
108
}
109