0

Get account usage

by
Published Dec 20, 2024

A summary of how each account is being transacted on exposing the level of detail and amounts attributable to manual adjustments.

Script xero Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Get account usage
7
 * A summary of how each account is being transacted on exposing the level of detail and amounts attributable to manual adjustments.
8
 */
9
export async function main(
10
	auth: Xero,
11
	startMonth: string | undefined,
12
	endMonth: string | undefined,
13
	xero_tenant_id: string
14
) {
15
	const url = new URL(`https://api.xero.com/finance.xro/1.0/AccountingActivities/AccountUsage`)
16
	for (const [k, v] of [
17
		['startMonth', startMonth],
18
		['endMonth', endMonth]
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