Update an academy's section sorting

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
	body: {
10
		previousIndex?: number
11
		newIndex?: number
12
		previousSectionIndex?: number
13
		newSectionIndex?: number
14
	}
15
) {
16
	const url = new URL(`https://actimo.com/api/v1/academy/${id}/section/sort`)
17

18
	const response = await fetch(url, {
19
		method: 'PUT',
20
		headers: {
21
			'api-key': auth.apiKey,
22
			'Content-Type': 'application/json'
23
		},
24
		body: JSON.stringify(body)
25
	})
26

27
	if (!response.ok) {
28
		const text = await response.text()
29
		throw new Error(`${response.status} ${text}`)
30
	}
31

32
	return await response.json()
33
}
34