0

Update a user

by
Published Oct 17, 2025

Update the details of a user.

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 a user
7
 * Update the details of a user.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  user_id: string,
12
  organization_id: string | undefined,
13
  body: { name: string; email: string; user_role?: string },
14
) {
15
  const url = new URL(`https://www.zohoapis.com/inventory/v1/users/${user_id}`);
16
  for (const [k, v] of [["organization_id", organization_id]]) {
17
    if (v !== undefined && v !== "" && k !== undefined) {
18
      url.searchParams.append(k, v);
19
    }
20
  }
21
  const response = await fetch(url, {
22
    method: "PUT",
23
    headers: {
24
      "Content-Type": "application/json",
25
      Authorization: "Zoho-oauthtoken " + auth.token,
26
    },
27
    body: JSON.stringify(body),
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35