0
Get content
One script reply has been approved by the moderators Verified
Created by hugo697 16 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 16 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	type: string | undefined,
9
	search: string | undefined,
10
	searchData: string | undefined,
11
	count: string | undefined,
12
	page: string | undefined,
13
	pageSize: string | undefined,
14
	all: string | undefined,
15
	tags: string | undefined,
16
	onlyTags: string | undefined,
17
	order: string | undefined,
18
	direction: string | undefined
19
) {
20
	const url = new URL(`https://actimo.com/api/v1/content/`)
21

22
	for (const [k, v] of [
23
		['type', type],
24
		['search', search],
25
		['searchData', searchData],
26
		['count', count],
27
		['page', page],
28
		['pageSize', pageSize],
29
		['all', all],
30
		['tags', tags],
31
		['onlyTags', onlyTags],
32
		['order', order],
33
		['direction', direction]
34
	]) {
35
		if (v !== undefined && v !== '' && k !== undefined) {
36
			url.searchParams.append(k, v)
37
		}
38
	}
39

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

48
	if (!response.ok) {
49
		const text = await response.text()
50
		throw new Error(`${response.status} ${text}`)
51
	}
52

53
	return await response.json()
54
}
55