Get an academy's training analytics drill down by type

Script actimo Verified

by hugo697 ยท 11/5/2024

The script

Submitted by hugo697 Bun
Verified 572 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	id: string,
9
	trainingId: string,
10
	department: string | undefined,
11
	group: string | undefined,
12
	limit: string | undefined,
13
	offset: string | undefined,
14
	order: string | undefined,
15
	search: string | undefined,
16
	templateMessageId: string | undefined,
17
	toggleValue: 'started' | 'not started' | 'completed' | 'not completed' | undefined,
18
	type: 'publishedTo' | 'opened' | 'passed' | undefined
19
) {
20
	const url = new URL(
21
		`https://actimo.com/api/v1/academy/${id}/training/${trainingId}/analytics/drillDown`
22
	)
23

24
	for (const [k, v] of [
25
		['department', department],
26
		['group', group],
27
		['limit', limit],
28
		['offset', offset],
29
		['order', order],
30
		['search', search],
31
		['templateMessageId', templateMessageId],
32
		['toggleValue', toggleValue],
33
		['type', type]
34
	]) {
35
		if (v !== undefined && v !== '' && k !== undefined) {
36
			url.searchParams.append(k, v)
37
		}
38
	}
39

40
	const response = await fetch(url, {
41
		method: 'GET',
42
		headers: {
43
			'api-key': auth.apiKey
44
		},
45
		body: undefined
46
	})
47

48
	if (!response.ok) {
49
		const text = await response.text()
50
		throw new Error(`${response.status} ${text}`)
51
	}
52

53
	return await response.json()
54
}
55