0

Generate loan summaries report

by
Published Oct 17, 2025

The _Generate loan summaries_ endpoint requests the generation of the Loan Summaries 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.

Script codat Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Codat = {
3
	encodedKey: string
4
}
5
/**
6
 * Generate loan summaries report
7
 * The _Generate loan summaries_ endpoint requests the generation of the Loan Summaries report.
8

9
Learn more about Codat's liabilities feature [here](https://docs.codat.io/lending/features/liabilities-overview).
10

11
Make sure you have [synced a company](https://docs.codat.io/lending-api#/operations/refresh-company-data) recently before calling the endpoint.
12

13
 */
14
export async function main(
15
	auth: Codat,
16
	companyId: string,
17
	sourceType: 'banking' | 'commerce' | 'accounting' | undefined
18
) {
19
	const url = new URL(`https://api.codat.io/companies/${companyId}/reports/liabilities/loans`)
20
	for (const [k, v] of [['sourceType', sourceType]]) {
21
		if (v !== undefined && v !== '' && k !== undefined) {
22
			url.searchParams.append(k, v)
23
		}
24
	}
25

26
	const response = await fetch(url, {
27
		method: 'POST',
28
		headers: {
29
			Authorization: `Basic ${auth.encodedKey}`
30
		},
31
		body: undefined
32
	})
33
	if (!response.ok) {
34
		const text = await response.text()
35
		throw new Error(`${response.status} ${text}`)
36
	}
37
	return await response.text()
38
}
39