1 | |
2 | type Actimo = { |
3 | apiKey: string |
4 | } |
5 |
|
6 | export async function main(auth: Actimo, id: string, templateMessageId: string | undefined) { |
7 | const url = new URL( |
8 | `https://actimo.com/api/v1/academy/${id}/analytics/publishedAcademyDepartments` |
9 | ) |
10 |
|
11 | for (const [k, v] of [['templateMessageId', templateMessageId]]) { |
12 | if (v !== undefined && v !== '' && k !== undefined) { |
13 | url.searchParams.append(k, v) |
14 | } |
15 | } |
16 |
|
17 | const response = await fetch(url, { |
18 | method: 'GET', |
19 | headers: { |
20 | 'api-key': auth.apiKey |
21 | }, |
22 | body: undefined |
23 | }) |
24 |
|
25 | if (!response.ok) { |
26 | const text = await response.text() |
27 | throw new Error(`${response.status} ${text}`) |
28 | } |
29 |
|
30 | return await response.json() |
31 | } |
32 |
|