1 | |
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 |
|