//native
type Xero = {
token: string
}
/**
* Retrieves an association object using a unique object ID
* By passing in the appropriate options, you can retrieve an association
*/
export async function main(
auth: Xero,
ObjectId: string,
pagesize: string | undefined,
page: string | undefined,
sort: 'Name' | 'CreatedDateUTC' | undefined,
direction: 'ASC' | 'DESC' | undefined,
xero_tenant_id: string
) {
const url = new URL(`https://api.xero.com/files.xro/1.0//Associations/${ObjectId}`)
for (const [k, v] of [
['pagesize', pagesize],
['page', page],
['sort', sort],
['direction', direction]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Accept: 'application/json',
'xero-tenant-id': xero_tenant_id,
Authorization: 'Bearer ' + auth.token
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 515 days ago