Get an academy's drill down by type
One script reply has been approved by the moderators Verified
Created by hugo697 403 days ago
Submitted by hugo697 Bun
Verified 403 days ago
1
//native
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
	limit: string | undefined,
12
	offset: string | undefined,
13
	order: string | undefined,
14
	search: string | undefined,
15
	templateMessageId: string | undefined,
16
	toggleValue: 'started' | 'not started' | 'completed' | 'not completed' | undefined,
17
	type: 'publishedTo' | 'started' | 'completed' | undefined
18
) {
19
	const url = new URL(`https://actimo.com/api/v1/academy/${id}/analytics/drillDown`)
20

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

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

45
	if (!response.ok) {
46
		const text = await response.text()
47
		throw new Error(`${response.status} ${text}`)
48
	}
49

50
	return await response.json()
51
}
52