0

Me projects get

by
Published Nov 5, 2024

Get all projects of mine

Script taskade Verified

The script

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

6
export async function main(
7
	auth: Taskade,
8
	limit: string | undefined,
9
	page: string | undefined,
10
	sort: 'viewed-asc' | 'viewed-desc' | undefined
11
) {
12
	const url = new URL(`https://www.taskade.com/api/v1/me/projects`)
13

14
	for (const [k, v] of [
15
		['limit', limit],
16
		['page', page],
17
		['sort', sort]
18
	]) {
19
		if (v !== undefined && v !== '' && k !== undefined) {
20
			url.searchParams.append(k, v)
21
		}
22
	}
23

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

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

37
	return await response.json()
38
}
39