//native
type Codat = {
encodedKey: string
}
/**
* Aged creditors report
* Returns aged creditors report for company that shows the total balance owed by a business to its suppliers over time.
*/
export async function main(
auth: Codat,
companyId: string,
reportDate: string | undefined,
numberOfPeriods: string | undefined,
periodLengthDays: string | undefined
) {
const url = new URL(`https://api.codat.io/companies/${companyId}/reports/agedCreditor`)
for (const [k, v] of [
['reportDate', reportDate],
['numberOfPeriods', numberOfPeriods],
['periodLengthDays', periodLengthDays]
]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'GET',
headers: {
Authorization: `Basic ${auth.encodedKey}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 235 days ago