0
Update contact profile settings
One script reply has been approved by the moderators Verified
Created by hugo697 2 days ago Viewed 0 times
0
Submitted by hugo697 Bun
Verified 2 days ago
1
//native
2
type Actimo = {
3
	apiKey: string
4
}
5

6
export async function main(
7
	auth: Actimo,
8
	targetId: string,
9
	sourceId: string | undefined,
10
	sourceAuthCode: string | undefined,
11
	body: { allow_email?: false | true; allow_sms?: false | true } & {
12
		allow_contact_info?: false | true
13
	}
14
) {
15
	const url = new URL(`https://actimo.com/api/v1/contacts/${targetId}/updateSettings`)
16

17
	for (const [k, v] of [
18
		['sourceId', sourceId],
19
		['sourceAuthCode', sourceAuthCode]
20
	]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25

26
	const response = await fetch(url, {
27
		method: 'PUT',
28
		headers: {
29
			'Content-Type': 'application/json'
30
		},
31
		body: JSON.stringify(body)
32
	})
33

34
	if (!response.ok) {
35
		const text = await response.text()
36
		throw new Error(`${response.status} ${text}`)
37
	}
38

39
	return await response.json()
40
}
41