Get Bank Statement Accounting

For lenders that prefer using bank statement data as the source of truth. We provide a data point that will allow access to customer bank statements, plus for reconciled bank transactions the matching accounting, invoice and billing data as well. As customers reconcile bank statements to invoices and bills, this transaction detail will provide valuable insight for lender's assessment measures.

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 Bank Statement Accounting
7
 * For lenders that prefer using bank statement data as the source of truth.  We provide a data point that will allow access to customer bank statements, plus for reconciled bank transactions the matching accounting, invoice and billing data as well.  As customers reconcile bank statements to invoices and bills, this transaction detail will provide valuable insight for lender's assessment measures.
8
 */
9
export async function main(
10
	auth: Xero,
11
	BankAccountID: string | undefined,
12
	FromDate: string | undefined,
13
	ToDate: string | undefined,
14
	SummaryOnly: string | undefined,
15
	xero_tenant_id: string
16
) {
17
	const url = new URL(`https://api.xero.com/finance.xro/1.0/BankStatementsPlus/statements`)
18
	for (const [k, v] of [
19
		['BankAccountID', BankAccountID],
20
		['FromDate', FromDate],
21
		['ToDate', ToDate],
22
		['SummaryOnly', SummaryOnly]
23
	]) {
24
		if (v !== undefined && v !== '' && k !== undefined) {
25
			url.searchParams.append(k, v)
26
		}
27
	}
28
	const response = await fetch(url, {
29
		method: 'GET',
30
		headers: {
31
			Accept: 'application/json',
32
			'xero-tenant-id': xero_tenant_id,
33
			Authorization: 'Bearer ' + auth.token
34
		},
35
		body: undefined
36
	})
37
	if (!response.ok) {
38
		const text = await response.text()
39
		throw new Error(`${response.status} ${text}`)
40
	}
41
	return await response.json()
42
}
43