Get Cash flow report

The statement of cash flows - direct method, provides the year to date changes in operating, financing and investing cash flow activities for an organisation. Cashflow statement is not available in US region at this stage.

Script xero Verified

by hugo697 ยท 12/20/2024

The script

Submitted by hugo697 Bun
Verified 515 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Get Cash flow report
7
 * The statement of cash flows - direct method, provides the year to date changes in operating, financing and investing cash flow activities for an organisation. Cashflow statement is not available in US region at this stage.
8
 */
9
export async function main(
10
	auth: Xero,
11
	startDate: string | undefined,
12
	endDate: string | undefined,
13
	xero_tenant_id: string
14
) {
15
	const url = new URL(`https://api.xero.com/finance.xro/1.0/FinancialStatements/Cashflow`)
16
	for (const [k, v] of [
17
		['startDate', startDate],
18
		['endDate', endDate]
19
	]) {
20
		if (v !== undefined && v !== '' && k !== undefined) {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'GET',
26
		headers: {
27
			Accept: 'application/json',
28
			'xero-tenant-id': xero_tenant_id,
29
			Authorization: 'Bearer ' + auth.token
30
		},
31
		body: undefined
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.json()
38
}
39