1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | post_id: string, |
9 | identifier_type: 'id' | 'external_id' | undefined |
10 | ) { |
11 | const url = new URL(`https://motimateapp.com/public_api/posts/${post_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 |
|