Get cash validation

Summarizes the total cash position for each account for an org

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 validation
7
 * Summarizes the total cash position for each account for an org
8
 */
9
export async function main(
10
	auth: Xero,
11
	balanceDate: string | undefined,
12
	asAtSystemDate: string | undefined,
13
	beginDate: string | undefined,
14
	xero_tenant_id: string
15
) {
16
	const url = new URL(`https://api.xero.com/finance.xro/1.0/CashValidation`)
17
	for (const [k, v] of [
18
		['balanceDate', balanceDate],
19
		['asAtSystemDate', asAtSystemDate],
20
		['beginDate', beginDate]
21
	]) {
22
		if (v !== undefined && v !== '' && k !== undefined) {
23
			url.searchParams.append(k, v)
24
		}
25
	}
26
	const response = await fetch(url, {
27
		method: 'GET',
28
		headers: {
29
			Accept: 'application/json',
30
			'xero-tenant-id': xero_tenant_id,
31
			Authorization: 'Bearer ' + auth.token
32
		},
33
		body: undefined
34
	})
35
	if (!response.ok) {
36
		const text = await response.text()
37
		throw new Error(`${response.status} ${text}`)
38
	}
39
	return await response.json()
40
}
41