0

Delete Package

by
Published Nov 5, 2024

Deletes a Package.

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

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

29
	return await response.text()
30
}
31