0

Update territories

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 territories
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  body: {
12
    territories?: {
13
      created_time: string;
14
      modified_time: string;
15
      manager: { name: string; id: string };
16
      reporting_to: { name: string; id: string };
17
      permission_type: "read_write_delete" | "read_only";
18
      modified_by: { name: string; id: string; email?: string };
19
      description: string;
20
      id: string;
21
      created_by: { name: string; id: string; email?: string };
22
      account_rule_criteria: {
23
        comparator: string;
24
        field: { api_name: string; id: string };
25
        value: {};
26
        group_operator: string;
27
        group: {}[];
28
      };
29
      deal_rule_criteria: {
30
        comparator: string;
31
        field: { api_name: string; id: string };
32
        value: {};
33
        group_operator: string;
34
        group: {}[];
35
      };
36
      lead_rule_criteria?: {
37
        comparator: string;
38
        field: { api_name: string; id: string };
39
        value: {};
40
        group_operator: string;
41
        group: {}[];
42
      };
43
      name: string;
44
      api_name: string;
45
    }[];
46
  },
47
) {
48
  const url = new URL(`https://zohoapis.com/crm/v8/settings/territories`);
49

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