Retrieves users

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
 * Retrieves users
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	where: string | undefined,
12
	order: string | undefined,
13
	xero_tenant_id: string,
14
	If_Modified_Since: string
15
) {
16
	const url = new URL(`https://api.xero.com/api.xro/2.0/Users`)
17
	for (const [k, v] of [
18
		['where', where],
19
		['order', order]
20
	]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25
	const response = await fetch(url, {
26
		method: 'GET',
27
		headers: {
28
			Accept: 'application/json',
29
			'xero-tenant-id': xero_tenant_id,
30
			'If-Modified-Since': If_Modified_Since,
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