0

Fetch Folders

by
Published Nov 5, 2024

Fetches Folders.

Script motimate Verified

The script

Submitted by hugo697 Bun
Verified 581 days ago
1
//native
2
type Motimate = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Motimate,
8
	filter_id_: string | undefined,
9
	filter_learning_type_: string | undefined,
10
	filter_created_at_lteq_: string | undefined,
11
	filter_updated_at_lteq_: string | undefined
12
) {
13
	const url = new URL(`https://motimateapp.com/public_api/folders`)
14

15
	for (const [k, v] of [
16
		['filter[id]', filter_id_],
17
		['filter[learning_type]', filter_learning_type_],
18
		['filter[created_at_lteq]', filter_created_at_lteq_],
19
		['filter[updated_at_lteq]', filter_updated_at_lteq_]
20
	]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25

26
	const response = await fetch(url, {
27
		method: 'GET',
28
		headers: {
29
			Authorization: 'Bearer ' + auth.token
30
		}
31
	})
32

33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37

38
	return await response.json()
39
}
40