0
Adds, updates or remove devices from a contact
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
	contactId: string,
9
	auth_code: string,
10
	body: {
11
		add?: {
12
			browser_type?: string
13
			device_type?: string
14
			id?: number
15
			push_key?: string
16
		}[]
17
		remove?: { id?: number; push_key?: string }[]
18
		update?: { id?: number; push_key?: string }[]
19
	}
20
) {
21
	const url = new URL(`https://actimo.com/api/v1/device/${contactId}`)
22

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

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

37
	return await response.json()
38
}
39