1 | |
2 | type Codat = { |
3 | encodedKey: string |
4 | } |
5 | |
6 | * Update data connection |
7 | * Update a data connection |
8 | */ |
9 | export async function main( |
10 | auth: Codat, |
11 | companyId: string, |
12 | connectionId: string, |
13 | body: { status?: 'PendingAuth' | 'Linked' | 'Unlinked' | 'Deauthorized' } |
14 | ) { |
15 | const url = new URL( |
16 | `https://api.codat.io/meta/companies/${companyId}/connections/${connectionId}` |
17 | ) |
18 |
|
19 | const response = await fetch(url, { |
20 | method: 'PATCH', |
21 | headers: { |
22 | 'Content-Type': 'application/json', |
23 | Authorization: `Basic ${auth.encodedKey}` |
24 | }, |
25 | body: JSON.stringify(body) |
26 | }) |
27 | if (!response.ok) { |
28 | const text = await response.text() |
29 | throw new Error(`${response.status} ${text}`) |
30 | } |
31 | return await response.json() |
32 | } |
33 |
|