Create group

Script actimo Verified

by hugo697 ยท 11/5/2024

The script

Submitted by hugo697 Bun
Verified 572 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

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

44
	const response = await fetch(url, {
45
		method: 'POST',
46
		headers: {
47
			'api-key': auth.apiKey,
48
			'Content-Type': 'application/json'
49
		},
50
		body: JSON.stringify(body)
51
	})
52

53
	if (!response.ok) {
54
		const text = await response.text()
55
		throw new Error(`${response.status} ${text}`)
56
	}
57

58
	return await response.json()
59
}
60