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

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

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

59
	return await response.json()
60
}
61