0

Delete a user from Grist

by
Published Apr 8, 2025

This action also deletes the user's personal organisation and all the workspaces and documents it contains. Currently, only the users themselves are allowed to delete their own accounts. ⚠️ **This action cannot be undone, please be cautious when using this endpoint** ⚠️

Script grist Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Grist = {
3
  apiKey: string;
4
  host: string;
5
};
6
/**
7
 * Delete a user from Grist
8
 * This action also deletes the user's personal organisation and all the workspaces and documents it contains.
9
Currently, only the users themselves are allowed to delete their own accounts.
10

11
⚠️ **This action cannot be undone, please be cautious when using this endpoint** ⚠️
12

13
 */
14
export async function main(
15
  auth: Grist,
16
  userId: string,
17
  body: { name: string },
18
) {
19
  const url = new URL(`https://${auth.host}/api/users/${userId}`);
20

21
  const response = await fetch(url, {
22
    method: "DELETE",
23
    headers: {
24
      "Content-Type": "application/json",
25
      Authorization: "Bearer " + auth.apiKey,
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.text();
34
}
35