0

Update User by ID

by
Published Oct 17, 2025

Updates a specific user by ID. #### Note *To delete a user, set deleted to true. You can un-delete by setting the deleted to null*

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update User by ID
7
 * Updates a specific user by ID.
8

9
####  Note
10
*To delete a user, set deleted to true.  You can un-delete by setting the deleted to null*
11
 */
12
export async function main(
13
  auth: Kustomer,
14
  id: string,
15
  body: {
16
    displayName?: string;
17
    avatarUrl?: string;
18
    name?: string;
19
    email?: string;
20
    mobile?: string;
21
    emailSignature?: string;
22
    deleted?: false | true;
23
    password?: string;
24
    currentPassword?: string;
25
    userType?: "user" | "limited" | "hourly";
26
    roleGroups?: string[];
27
    roles?: string[];
28
  },
29
) {
30
  const url = new URL(`https://api.kustomerapp.com/v1/users/${id}`);
31

32
  const response = await fetch(url, {
33
    method: "PUT",
34
    headers: {
35
      "Content-Type": "application/json",
36
      Authorization: "Bearer " + auth.apiKey,
37
    },
38
    body: JSON.stringify(body),
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.json();
45
}
46