0

Add member to group

by
Published Nov 5, 2024

Add contact with contactId to group with Id and optionally update contact with request body values

Script actimo Verified

The script

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

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

39
	const response = await fetch(url, {
40
		method: 'PUT',
41
		headers: {
42
			'api-key': auth.apiKey,
43
			'Content-Type': 'application/json'
44
		},
45
		body: JSON.stringify(body)
46
	})
47

48
	if (!response.ok) {
49
		const text = await response.text()
50
		throw new Error(`${response.status} ${text}`)
51
	}
52

53
	return await response.json()
54
}
55