//native
type Codat = {
encodedKey: string
}
/**
* List loan transactions
* The *List loan transactions* endpoint returns all [loan transactions](https://docs.codat.io/lending-api#/schemas/LoanTransactions) identified from a company's accounting, banking, and commerce integrations.
This detail gives analysts a better idea of the loan obligations a company may have.
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: '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