0

Get user activities

by
Published Dec 20, 2024

For a specified organisation, provides a list of all the users registered, and a history of their accounting transactions. Also identifies the existence of an external accounting advisor and the level of interaction.

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 user activities
7
 * For a specified organisation, provides a list of all the users registered, and a history of their accounting transactions. Also identifies the existence of an external accounting advisor and the level of interaction.
8
 */
9
export async function main(auth: Xero, dataMonth: string | undefined, xero_tenant_id: string) {
10
	const url = new URL(`https://api.xero.com/finance.xro/1.0/AccountingActivities/UserActivities`)
11
	for (const [k, v] of [['dataMonth', dataMonth]]) {
12
		if (v !== undefined && v !== '' && k !== undefined) {
13
			url.searchParams.append(k, v)
14
		}
15
	}
16
	const response = await fetch(url, {
17
		method: 'GET',
18
		headers: {
19
			Accept: 'application/json',
20
			'xero-tenant-id': xero_tenant_id,
21
			Authorization: 'Bearer ' + auth.token
22
		},
23
		body: undefined
24
	})
25
	if (!response.ok) {
26
		const text = await response.text()
27
		throw new Error(`${response.status} ${text}`)
28
	}
29
	return await response.json()
30
}
31