0
Export contacts to excel file (.xls)
One script reply has been approved by the moderators Verified
Created by hugo697 40 days ago Viewed 7 times
0
Submitted by hugo697 Bun
Verified 40 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(auth: Actimo, ids: string | undefined, fields: string | undefined) {
7
	const url = new URL(`https://actimo.com/api/v1/contacts/export/all/excel`)
8

9
	for (const [k, v] of [
10
		['ids', ids],
11
		['fields', fields]
12
	]) {
13
		if (v !== undefined && v !== '' && k !== undefined) {
14
			url.searchParams.append(k, v)
15
		}
16
	}
17

18
	const response = await fetch(url, {
19
		method: 'GET',
20
		headers: {
21
			'api-key': auth.apiKey
22
		},
23
		body: undefined
24
	})
25

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

31
	return await response.text()
32
}
33