1 | |
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main( |
7 | auth: Actimo, |
8 | contactId: string, |
9 | type: string, |
10 | action: string, |
11 | auth_code: string, |
12 | body: { data?: { browserId?: string; clientId?: number; pushKey?: string } } |
13 | ) { |
14 | const url = new URL( |
15 | `https://actimo.com/api/v1/device/${contactId}/register-action/${type}/${action}` |
16 | ) |
17 |
|
18 | const response = await fetch(url, { |
19 | method: 'PUT', |
20 | headers: { |
21 | 'auth-code': auth_code, |
22 | 'Content-Type': 'application/json' |
23 | }, |
24 | body: JSON.stringify(body) |
25 | }) |
26 |
|
27 | if (!response.ok) { |
28 | const text = await response.text() |
29 | throw new Error(`${response.status} ${text}`) |
30 | } |
31 |
|
32 | return await response.json() |
33 | } |
34 |
|