0

Delete Moti Chapter Completion

by
Published Nov 5, 2024

Deletes a Moti Chapter Completion.

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
	completion_id: string,
9
	identifier_type: 'id' | 'external_id' | undefined
10
) {
11
	const url = new URL(
12
		`https://motimateapp.com/public_api/motis/chapter_completions/${completion_id}`
13
	)
14
	for (const [k, v] of [['identifier_type', identifier_type]]) {
15
		if (v !== undefined && v !== '' && k !== undefined) {
16
			url.searchParams.append(k, v)
17
		}
18
	}
19
	const response = await fetch(url, {
20
		method: 'DELETE',
21
		headers: {
22
			Authorization: 'Bearer ' + auth.token
23
		}
24
	})
25

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

31
	return await response.text()
32
}
33