1 | |
2 | type Motimate = { |
3 | token: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Motimate, |
8 | body: { |
9 | external_id?: string |
10 | kind?: 'country' | 'custom' | 'organization' | 'region' | 'store' |
11 | name?: string |
12 | excluded_from_scoreboard?: false | true |
13 | imported?: false | true |
14 | parent_id?: number |
15 | parent_external_id?: number |
16 | } |
17 | ) { |
18 | const url = new URL(`https://motimateapp.com/public_api/groups`) |
19 |
|
20 | const response = await fetch(url, { |
21 | method: 'POST', |
22 | headers: { |
23 | 'Content-Type': 'application/json', |
24 | Authorization: 'Bearer ' + auth.token |
25 | }, |
26 | body: JSON.stringify(body) |
27 | }) |
28 |
|
29 | if (!response.ok) { |
30 | const text = await response.text() |
31 | throw new Error(`${response.status} ${text}`) |
32 | } |
33 |
|
34 | return await response.json() |
35 | } |
36 |
|