0
Get an academy's published departments
One script reply has been approved by the moderators Verified
Created by hugo697 239 days ago Viewed 13523 times
0
Submitted by hugo697 Bun
Verified 239 days ago
1
//native
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