0

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

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