0

Delete User

by
Published Nov 5, 2024

Deletes a User.

Script motimate Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Motimate = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Motimate,
8
	user_id: string,
9
	force: string | undefined,
10
	identifier_type: 'id' | 'external_id' | undefined
11
) {
12
	const url = new URL(`https://motimateapp.com/public_api/users/${user_id}`)
13
	for (const [k, v] of [
14
		['force', force],
15
		['identifier_type', identifier_type]
16
	]) {
17
		if (v !== undefined && v !== '' && k !== undefined) {
18
			url.searchParams.append(k, v)
19
		}
20
	}
21
	const response = await fetch(url, {
22
		method: 'DELETE',
23
		headers: {
24
			Authorization: 'Bearer ' + auth.token
25
		}
26
	})
27

28
	if (!response.ok) {
29
		const text = await response.text()
30
		throw new Error(`${response.status} ${text}`)
31
	}
32

33
	return await response.text()
34
}
35