1 | |
2 | type Codat = { |
3 | encodedKey: string |
4 | } |
5 | |
6 | * Set configuration |
7 | * Use *Set configuration* endpoint to configure a given company ID. |
8 | */ |
9 | export async function main( |
10 | auth: Codat, |
11 | companyId: string, |
12 | body: { |
13 | companyId?: string |
14 | accountingSoftwareCompanyName?: string |
15 | enabled?: false | true |
16 | configured?: false | true |
17 | schedule?: { |
18 | selectedFrequency?: string |
19 | frequencyOptions?: string[] |
20 | startDate?: string |
21 | syncHourUtc?: number |
22 | timeZoneIanaId?: string |
23 | } |
24 | configuration?: { |
25 | syncAsBankFeeds?: { |
26 | enableSync?: false | true |
27 | selectedBankAccountId?: string |
28 | bankAccountOptions?: { |
29 | id?: string |
30 | name?: string |
31 | accountType?: string |
32 | }[] |
33 | } |
34 | syncAsExpenses?: { |
35 | enableSync?: false | true |
36 | supplier?: { |
37 | selectedSupplierId?: string |
38 | supplierOptions?: { id?: string; name?: string }[] |
39 | } |
40 | customer?: { |
41 | selectedCustomerId?: string |
42 | customerOptions?: { id?: string; name?: string }[] |
43 | } |
44 | selectedBankAccountId?: string |
45 | bankAccountOptions?: { |
46 | id?: string |
47 | name?: string |
48 | accountType?: string |
49 | }[] |
50 | } |
51 | } |
52 | } |
53 | ) { |
54 | const url = new URL(`https://api.codat.io/companies/${companyId}/sync/banking/config`) |
55 |
|
56 | const response = await fetch(url, { |
57 | method: 'POST', |
58 | headers: { |
59 | 'Content-Type': 'application/json', |
60 | Authorization: `Basic ${auth.encodedKey}` |
61 | }, |
62 | body: JSON.stringify(body) |
63 | }) |
64 | if (!response.ok) { |
65 | const text = await response.text() |
66 | throw new Error(`${response.status} ${text}`) |
67 | } |
68 | return await response.json() |
69 | } |
70 |
|