0
Add members to group
One script reply has been approved by the moderators Verified
Created by hugo697 185 days ago Viewed 12692 times
0
Submitted by hugo697 Bun
Verified 185 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	id: string,
9
	overwriteGroups: string | undefined,
10
	ignoreEmptyValues: string | undefined,
11
	body: {
12
		addr_city?: string
13
		addr_country?: string
14
		addr_line_1?: string
15
		addr_line_2?: string
16
		addr_state?: string
17
		addr_zip?: string
18
		company?: string
19
		company_reg?: string
20
		country_code?: string
21
		data1?: string
22
		data2?: string
23
		data3?: string
24
		department?: string
25
		email?: string
26
		employee_id?: number
27
		first_name?: string
28
		last_name?: string
29
		manager_id?: number
30
		manager_name?: string
31
		manager_type?: string
32
		phone_number?: string
33
		timezone?: string
34
		title?: string
35
		'{data3-data20}'?: string
36
	}[]
37
) {
38
	const url = new URL(`https://actimo.com/api/v1/groups/${id}/members`)
39

40
	for (const [k, v] of [
41
		['overwriteGroups', overwriteGroups],
42
		['ignoreEmptyValues', ignoreEmptyValues]
43
	]) {
44
		if (v !== undefined && v !== '' && k !== undefined) {
45
			url.searchParams.append(k, v)
46
		}
47
	}
48

49
	const response = await fetch(url, {
50
		method: 'POST',
51
		headers: {
52
			'api-key': auth.apiKey,
53
			'Content-Type': 'application/json'
54
		},
55
		body: JSON.stringify(body)
56
	})
57

58
	if (!response.ok) {
59
		const text = await response.text()
60
		throw new Error(`${response.status} ${text}`)
61
	}
62

63
	return await response.json()
64
}
65