//native
type Codat = {
encodedKey: string
}
/**
* Generate loan transactions report
* The _Generate loan transactions_ endpoint requests the generation of the Loan Transactions report.
Learn more about Codat's liabilities feature [here](https://docs.codat.io/lending/features/liabilities-overview).
Make sure you have [synced a company](https://docs.codat.io/lending-api#/operations/refresh-company-data) recently before calling the endpoint.
*/
export async function main(
auth: Codat,
companyId: string,
sourceType: 'banking' | 'commerce' | 'accounting' | undefined
) {
const url = new URL(
`https://api.codat.io/companies/${companyId}/reports/liabilities/loans/transactions`
)
for (const [k, v] of [['sourceType', sourceType]]) {
if (v !== undefined && v !== '' && k !== undefined) {
url.searchParams.append(k, v)
}
}
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Basic ${auth.encodedKey}`
},
body: undefined
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.text()
}
Submitted by hugo697 235 days ago