0

Update territory

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

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