0

Create views

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
 * Create views
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  _module: string | undefined,
12
  body: {
13
    custom_views: {
14
      display_value: string;
15
      system_name: string;
16
      category: string;
17
      created_time: string;
18
      modified_time: string;
19
      last_accessed_time: string;
20
      name: string;
21
      created_by: { name: string; id: string; email?: string };
22
      modified_by: { name: string; id: string; email?: string };
23
      module: { name: string; id: string; email?: string };
24
      criteria: {
25
        comparator: string;
26
        field: { api_name: string; id: string };
27
        value: {};
28
        group_operator: string;
29
        group: {}[];
30
      };
31
      default: false | true;
32
      system_defined: false | true;
33
      locked: false | true;
34
      favorite: number;
35
      offline: false | true;
36
      access_type: "shared" | "public" | "only_to_me";
37
      shared_to: {
38
        type: "territories" | "roles" | "groups" | "users";
39
        name: string;
40
        id: string;
41
        subordinates: false | true;
42
      }[];
43
      fields: { id: string; api_name: string; _pin: false | true }[];
44
      sort_by: { id: string; api_name: string };
45
      sort_order: "asc" | "desc";
46
      id: string;
47
    }[];
48
  },
49
) {
50
  const url = new URL(`https://zohoapis.com/crm/v8/settings/custom_views`);
51
  for (const [k, v] of [["module", _module]]) {
52
    if (v !== undefined && v !== "" && k !== undefined) {
53
      url.searchParams.append(k, v);
54
    }
55
  }
56
  const response = await fetch(url, {
57
    method: "POST",
58
    headers: {
59
      "Content-Type": "application/json",
60
      Authorization: "Zoho-oauthtoken " + auth.token,
61
    },
62
    body: JSON.stringify(body),
63
  });
64
  if (!response.ok) {
65
    const text = await response.text();
66
    throw new Error(`${response.status} ${text}`);
67
  }
68
  return await response.json();
69
}
70