1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | post_id: string, |
9 | body: { |
10 | text?: string |
11 | group_id?: number |
12 | group_external_id?: string |
13 | user_id?: number |
14 | user_external_id?: string |
15 | } |
16 | ) { |
17 | const url = new URL(`https://motimateapp.com/public_api/posts/${post_id}`) |
18 |
|
19 | const response = await fetch(url, { |
20 | method: 'PATCH', |
21 | headers: { |
22 | 'Content-Type': 'application/json', |
23 | Authorization: 'Bearer ' + auth.token |
24 | }, |
25 | body: JSON.stringify(body) |
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.json() |
34 | } |
35 |
|