0

Create a user

by
Published Oct 17, 2025

Create a user for your organization.

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