0

Create user type

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 user type
7
 *
8
 */
9
export async function main(
10
  auth: Zoho,
11
  portal: string,
12
  body: {
13
    user_type: {
14
      personality_module: {
15
        api_name: string;
16
        id: string;
17
        plural_label: string;
18
      };
19
      created_time: string;
20
      modified_time: string;
21
      modified_by: { name: string; id: string };
22
      created_by: { name: string; id: string };
23
      name: string;
24
      active: false | true;
25
      default: false | true;
26
      no_of_users: number;
27
      id: string;
28
      modules: {
29
        id: string;
30
        plural_label: string;
31
        shared_type: string;
32
        api_name: string;
33
        filters: { display_label: string; api_name: string; id: string }[];
34
        fields: { read_only: false | true; api_name: string; id: string }[];
35
        layouts: {
36
          display_label: string;
37
          name: string;
38
          id: string;
39
          _default_view: {
40
            display_label: string;
41
            name: string;
42
            id: string;
43
            type: string;
44
          };
45
        }[];
46
        views: {
47
          display_label: string;
48
          name: string;
49
          id: string;
50
          type: string;
51
        };
52
        permissions: {
53
          view: false | true;
54
          edit: false | true;
55
          edit_shared_records: false | true;
56
          create: false | true;
57
          delete: false | true;
58
          delete_attachment: false | true;
59
          create_attachment: false | true;
60
        };
61
      }[];
62
    }[];
63
  },
64
) {
65
  const url = new URL(
66
    `https://zohoapis.com/crm/v8/settings/portals/${portal}/user_type`,
67
  );
68

69
  const response = await fetch(url, {
70
    method: "POST",
71
    headers: {
72
      "Content-Type": "application/json",
73
      Authorization: "Zoho-oauthtoken " + auth.token,
74
    },
75
    body: JSON.stringify(body),
76
  });
77
  if (!response.ok) {
78
    const text = await response.text();
79
    throw new Error(`${response.status} ${text}`);
80
  }
81
  return await response.json();
82
}
83