Add contact relationships

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
	contactId: string,
9
	body: {
10
		changes?: { '(relationship-type)'?: { id?: number; contactType?: string } }
11
	}
12
) {
13
	const url = new URL(`https://actimo.com/api/v1/contacts/${contactId}/relationships`)
14

15
	const response = await fetch(url, {
16
		method: 'PUT',
17
		headers: {
18
			'api-key': auth.apiKey,
19
			'Content-Type': 'application/json'
20
		},
21
		body: JSON.stringify(body)
22
	})
23

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

29
	return await response.json()
30
}
31