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