1 | |
2 | type Codat = { |
3 | encodedKey: string |
4 | } |
5 | |
6 | * Get cash flow statement |
7 | * Gets the latest cash flow statement for a company. |
8 | */ |
9 | export async function main( |
10 | auth: Codat, |
11 | companyId: string, |
12 | periodLength: string | undefined, |
13 | periodsToCompare: string | undefined, |
14 | startMonth: string | undefined |
15 | ) { |
16 | const url = new URL( |
17 | `https://api.codat.io/companies/${companyId}/data/financials/cashFlowStatement` |
18 | ) |
19 | for (const [k, v] of [ |
20 | ['periodLength', periodLength], |
21 | ['periodsToCompare', periodsToCompare], |
22 | ['startMonth', startMonth] |
23 | ]) { |
24 | if (v !== undefined && v !== '' && k !== undefined) { |
25 | url.searchParams.append(k, v) |
26 | } |
27 | } |
28 |
|
29 | const response = await fetch(url, { |
30 | method: 'GET', |
31 | headers: { |
32 | Authorization: `Basic ${auth.encodedKey}` |
33 | }, |
34 | body: undefined |
35 | }) |
36 | if (!response.ok) { |
37 | const text = await response.text() |
38 | throw new Error(`${response.status} ${text}`) |
39 | } |
40 | return await response.json() |
41 | } |
42 |
|