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

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

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

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

45
	if (!response.ok) {
46
		const text = await response.text()
47
		throw new Error(`${response.status} ${text}`)
48
	}
49

50
	return await response.json()
51
}
52