//native
type Codat = {
encodedKey: string
}
/**
* Get loan summaries
* The *Get loan summaries* endpoint returns a summary by integration type of all loans identified from a company's accounting, banking, and commerce integrations.
The endpoint returns a list of a company's [loan summaries](https://docs.codat.io/lending-api#/schemas/LoanSummary) for each valid data connection.
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`)
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