0

Searches for feed connections

by
Published Dec 20, 2024

By passing in the appropriate options, you can search for available feed connections in the system.

Script xero Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Searches for feed connections
7
 * By passing in the appropriate options, you can search for available feed connections in the system.
8
 */
9
export async function main(
10
	auth: Xero,
11
	page: string | undefined,
12
	pageSize: string | undefined,
13
	Xero_Tenant_Id: string
14
) {
15
	const url = new URL(`https://api.xero.com/bankfeeds.xro/1.0/FeedConnections`)
16
	for (const [k, v] of [
17
		['page', page],
18
		['pageSize', pageSize]
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