Edits history of script submission #23055 for ' Delete User (gworkspace)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Delete User
     * 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.
     */
    export async function main(auth: RT.Gworkspace, user_key: string) {
      const response = await fetch(
        `https://admin.googleapis.com/admin/directory/v1/users/${encodeURIComponent(user_key)}`,
        {
          method: "DELETE",
          headers: { Authorization: `Bearer ${auth.token}` },
        },
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return { success: true }
    }
    

    Submitted by hugo989 1 hour ago