0

Delete User

by
Published today

Delete a user. The account can be restored for 20 days (users.undelete); after that it and its data are gone. To keep the data, suspend the user instead.

Script gworkspace Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 1 hour ago
1
//native
2

3
/**
4
 * Delete User
5
 * Delete a user. The account can be restored for 20 days (users.undelete); after that it and its data are gone. To keep the data, suspend the user instead.
6
 */
7
export async function main(auth: RT.Gworkspace, user_key: string) {
8
  const response = await fetch(
9
    `https://admin.googleapis.com/admin/directory/v1/users/${encodeURIComponent(user_key)}`,
10
    {
11
      method: "DELETE",
12
      headers: { Authorization: `Bearer ${auth.token}` },
13
    },
14
  )
15

16
  if (!response.ok) {
17
    throw new Error(`${response.status} ${await response.text()}`)
18
  }
19

20
  return { success: true }
21
}
22